medusajs/medusa · error · MedusaError

Auth identity not found

Error message

Auth identity not found

What it means

getCustomerAuthIdentityStep throws NOT_FOUND when the first entry of the authIdentities array is empty — the customer has no linked auth identity to operate on.

Source

Thrown at packages/core/core-flows/src/customer/workflows/remove-customer-account.ts:43

interface GetCustomerAuthIdentityStepInput {
  authIdentities: {
    id: string
    app_metadata?: Record<string, unknown>
    provider_identities?: { entity_id: string }[]
  }[]
}

/**
 * This step returns the customer's auth identity from a queried list. It throws
 * an error if no auth identity is found.
 */
export const getCustomerAuthIdentityStep = createStep(
  "get-customer-auth-identity",
  async ({ authIdentities }: GetCustomerAuthIdentityStepInput) => {
    const authIdentity = authIdentities[0]

    if (!authIdentity) {
      throw new MedusaError(
        MedusaError.Types.NOT_FOUND,
        "Auth identity not found"
      )
    }

    return new StepResponse(authIdentity)
  }
)

export const removeCustomerAccountWorkflowId = "remove-customer-account"
/**
 * This workflow deletes a customer and remove its association to its auth identity. It's used by the
 * [Delete Customer Admin API Route](https://docs.medusajs.com/api/admin/customers/delete-a-customer).
 *
 * You can use this workflow within your customizations or your own custom workflows, allowing you to
 * delete customer accounts within your custom flows.
 *
 * :::note

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Verify the customer has a linked auth identity before invoking the workflow (query auth identity via the auth module or customer with auth identities)
  2. If the identity is already gone, remove the customer directly with deleteCustomerWorkflow
  3. Guard against empty authIdentities in your caller and choose the customer-only deletion path

Example fix

// before
await removeCustomerAccountWorkflow(container).run({ input: { id, authIdentities: [] } })

// after
if (!authIdentities.length) {
  await deleteCustomerWorkflow(container).run({ input: { ids: [id] } })
} else {
  await removeCustomerAccountWorkflow(container).run({ input: { id, authIdentities } })
}
Defensive patterns

Strategy: type-guard

Validate before calling

const authIdentity = input.authIdentities?.[0]
if (!authIdentity) { /* skip auth deletion, only delete customer */ }

Type guard

const hasAuthIdentity = (i: { authIdentities?: unknown[] }) => !!i?.authIdentities?.[0]

Try / catch

try { await removeCustomerAccountWorkflow(scope).run({ input }) } catch (e) { if (e.type === MedusaError.Types.NOT_FOUND && /Auth identity/.test(e.message)) { await deleteCustomerWorkflow(scope).run({ input: { ids: [id] } }) } throw e }

Prevention

When it happens

Trigger: Running removeCustomerAccountWorkflow (or any workflow embedding getCustomerAuthIdentityStep) for a customer whose auth identity list is empty (guest customer, deleted/unlinked auth identity).

Common situations: Deleting a guest customer that never had an auth identity; auth identity already removed by a prior delete or unlink; customer created by admin/seeder without an auth link.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/dc31f0a4b774b79f. Report an issue: GitHub.