hcengineering/platform · error

Confirmed social identity is attached to the wrong person

Error message

Confirmed social identity is attached to the wrong person

What it means

ensureEmployeeForPerson validates that a confirmed (verifiedOn set) social identity is not attached to a different person than the one being processed. Unconfirmed identities may move between persons (merge scenarios), but confirmed ones must not, so the function throws to protect data integrity until an accounts-merge feature exists.

Source

Thrown at plugins/contact/src/utils.ts:528

                attachedToClass: contact.class.Person,
                collection: 'socialIds',
                type: socialId.type,
                value: socialId.value,
                key: buildSocialIdString(socialId), // TODO: fill it in trigger or on DB level as stored calculated column or smth?
                verifiedOn: socialId.verifiedOn,
                isDeleted: socialId.isDeleted ?? false
              },
              socialId._id as SocialIdentityRef
            )
          )
          await client.tx(createSocialIdTx)
        })
      } else {
        // If not confirmed locally can be attached to a different person (persons merge scenario)
        // Confirmed social identity should not be attached to a different person for now
        // It will change with accounts merge function
        if (existing.verifiedOn != null && existing.attachedTo !== personRef) {
          throw new Error('Confirmed social identity is attached to the wrong person')
        }

        // Check and update if needed. It can:
        // 1. Become verified (maybe with persons merge) (changes verifiedOn, attachedTo)
        const sidUpdate: DocumentUpdate<SocialIdentity> = {}
        let needUpdate = false

        // become verified
        if (existing.verifiedOn == null) {
          sidUpdate.verifiedOn = socialId.verifiedOn
          needUpdate = true
        }

        // merged from another person
        if (existing.attachedTo !== personRef) {
          sidUpdate.attachedTo = personRef
          // Bump collection in Person?
          needUpdate = true

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the correct person owns the confirmed identity; unmerge or detach the identity from the wrong person first
  2. Reset verifiedOn (unconfirm) the identity if it genuinely needs reassignment, then re-verify under the right person
  3. Skip or reconcile the conflicting person before running the merge
  4. Fix upstream merge logic so identities are re-pointed before ensureEmployee runs

Example fix

// before
await ensureEmployee(client, personA) // identity.verifiedOn set, attachedTo = personB
// after
await client.update(identity, { attachedTo: personA, verifiedOn: Date.now() })
await ensureEmployee(client, personA)
Defensive patterns

Strategy: validation

Validate before calling

const existing = identities.find(i => i.key === sid)
if (existing?.verifiedOn != null && existing.attachedTo !== person._id) {
  // reconcile identity ownership before calling ensureEmployee
}

Type guard

function isSafeToAttach(identity: SocialIdentity | undefined, personRef: Ref<Person>): boolean {
  return identity === undefined || identity.verifiedOn == null || identity.attachedTo === personRef
}

Try / catch

try {
  await ensureEmployee(client, person)
} catch (err) {
  if (err.message.includes('Confirmed social identity is attached to the wrong person')) {
    // resolve identity ownership conflict manually / via admin tooling
  }
  throw err
}

Prevention

When it happens

Trigger: Merging or re-attributing persons where a SocialIdentity has verifiedOn set and attachedTo pointing at a different personRef than the target person; calling ensureEmployee for a person whose identity record belongs to someone else.

Common situations: Duplicate-person cleanup scripts merging two employees who shared a verified social login; import/migration tooling re-linking identities; concurrent person-merge operations racing.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/75b1d69950aa14ac. Report an issue: GitHub.