{"record":{"id":"09c0e93b50c29589","repo":"medusajs/medusa","slug":"multiple-authidentities-found-for-entity-id-ent","errorCode":null,"errorMessage":"Multiple authIdentities found for entity_id \"${entity_id}\"","messagePattern":"Multiple authIdentities found for entity_id \"(.+?)\"","errorType":"exception","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/modules/auth/src/services/auth-module.ts","lineNumber":1175,"sourceCode":"            provider_identities: {\n              entity_id,\n              provider,\n            },\n          },\n          {\n            relations: [\"provider_identities\"],\n          }\n        )\n\n        if (!authIdentities.length) {\n          throw new MedusaError(\n            MedusaError.Types.NOT_FOUND,\n            `AuthIdentity with entity_id \"${entity_id}\" not found`\n          )\n        }\n\n        if (authIdentities.length > 1) {\n          throw new MedusaError(\n            MedusaError.Types.INVALID_DATA,\n            `Multiple authIdentities found for entity_id \"${entity_id}\"`\n          )\n        }\n\n        const providerIdentityData = authIdentities[0].provider_identities.find(\n          (pi) => pi.provider === provider\n        )\n\n        if (!providerIdentityData) {\n          throw new MedusaError(\n            MedusaError.Types.NOT_FOUND,\n            `ProviderIdentity with entity_id \"${entity_id}\" not found`\n          )\n        }\n\n        const updatedProviderIdentity =\n          await this.providerIdentityService_.update({","sourceCodeStart":1157,"sourceCodeEnd":1193,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/auth/src/services/auth-module.ts#L1157-L1193","documentation":"INVALID_DATA thrown when the entity_id-based lookup returns more than one auth identity. entity_id is expected to be unique per auth identity; duplicates make the target ambiguous, so the operation refuses to proceed.","triggerScenarios":"Two or more auth identities sharing the same entity_id (from a bug in registration logic or manual DB edits); concurrent sign-ups racing an existence check and both inserting.","commonSituations":"Custom registration flows without uniqueness constraints on entity_id; direct SQL inserts/imports creating duplicates; missing unique index after a module version upgrade.","solutions":["Find and merge/remove duplicate auth identities for the entity_id (listAuthIdentities, keep the correct one)","Add a uniqueness guarantee in your registration flow before insert","If the schema lacks it, add/verify a unique constraint on auth_identity.entity_id"],"exampleFix":"// before\nawait authModule.updateProviderIdentityByEntityId(entityId, provider, data)\n// after\nconst dupes = await authModule.listAuthIdentities({ entity_id: entityId })\nif (dupes.length > 1) {\n  await authModule.deleteAuthIdentities(dupes.slice(1).map((d) => d.id))\n}\nawait authModule.updateProviderIdentityByEntityId(entityId, provider, data)","handlingStrategy":"validation","validationCode":"const dupes = await authModule.listAuthIdentities({ entity_id: entityId })\nif (dupes.length > 1) throw new Error('Duplicate auth identities — merge first')","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Enforce uniqueness of entity_id in registration","Audit for duplicates after data imports"],"tags":["auth","identity","duplicate-data"],"backgroundTag":"duplicate-unique-key","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}