medusajs/medusa · error · MedusaError
Multiple authIdentities found for entity_id "${entity_id}"
Error message
Multiple authIdentities found for entity_id "${entity_id}" What it means
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.
Source
Thrown at packages/modules/auth/src/services/auth-module.ts:1175
provider_identities: {
entity_id,
provider,
},
},
{
relations: ["provider_identities"],
}
)
if (!authIdentities.length) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`AuthIdentity with entity_id "${entity_id}" not found`
)
}
if (authIdentities.length > 1) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Multiple authIdentities found for entity_id "${entity_id}"`
)
}
const providerIdentityData = authIdentities[0].provider_identities.find(
(pi) => pi.provider === provider
)
if (!providerIdentityData) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`ProviderIdentity with entity_id "${entity_id}" not found`
)
}
const updatedProviderIdentity =
await this.providerIdentityService_.update({View on GitHub (pinned to 5e06e544a2)
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
Example fix
// before
await authModule.updateProviderIdentityByEntityId(entityId, provider, data)
// after
const dupes = await authModule.listAuthIdentities({ entity_id: entityId })
if (dupes.length > 1) {
await authModule.deleteAuthIdentities(dupes.slice(1).map((d) => d.id))
}
await authModule.updateProviderIdentityByEntityId(entityId, provider, data) Defensive patterns
Strategy: validation
Validate before calling
const dupes = await authModule.listAuthIdentities({ entity_id: entityId })
if (dupes.length > 1) throw new Error('Duplicate auth identities — merge first') Type guard
null
Try / catch
null
Prevention
- Enforce uniqueness of entity_id in registration
- Audit for duplicates after data imports
When it happens
Trigger: 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.
Common situations: Custom registration flows without uniqueness constraints on entity_id; direct SQL inserts/imports creating duplicates; missing unique index after a module version upgrade.
Related errors
- AuthIdentity with entity_id "${entity_id}" not found
- Customer with this email already has an account
- The user is already authenticated and cannot accept an invit
- User ID not found
- User with id: ${id} was not found
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/09c0e93b50c29589.
Report an issue: GitHub.