nextauthjs/next-auth · error · AuthError

Error creating or finding account

Error message

Error creating or finding account

What it means

AuthError('Error creating or finding account') is a defensive guard thrown when, after adapter linkAccount/getAccount operations, the account is still null. The comment in source states it is 'mostly for type checking' — under normal operation the adapter layer guarantees an account exists, so hitting it indicates an adapter returned null where the type system assumed it could not.

Source

Thrown at packages/core/src/lib/actions/callback/index.ts:450

      // Check if user is allowed to sign in
      await handleAuthorized({ user, account }, options)

      // Sign user in, creating them and their account if needed
      const {
        user: loggedInUser,
        isNewUser,
        session,
        account: currentAccount,
      } = await handleLoginOrRegister(
        sessionStore.value,
        user,
        account,
        options
      )

      if (!currentAccount) {
        // This is mostly for type checking. It should never actually happen.
        throw new AuthError("Error creating or finding account")
      }

      // Create new authenticator if needed
      if (authenticator && loggedInUser.id) {
        await localOptions.adapter.createAuthenticator({
          ...authenticator,
          userId: loggedInUser.id,
        })
      }

      // Do the session registering dance
      if (useJwtSession) {
        const defaultToken = {
          name: loggedInUser.name,
          email: loggedInUser.email,
          picture: loggedInUser.image,
          sub: loggedInUser.id?.toString(),
        }

View on GitHub (pinned to a1a16a5a77)

Solutions

  1. Verify the adapter's createAccount/getAccount return the account object and never resolve null on success
  2. Update or replace the custom adapter with an official one matching your @auth/core major version
  3. Check adapter/database logs for swallowed errors (constraint violations, connection failures) during account creation
  4. Enable Auth.js debug logging (logger debug level) to trace which adapter call returned null

Example fix

// before (custom adapter)
async createAccount(account) { await db.accounts.insert(account) }
// after
async createAccount(account) {
  const created = await db.accounts.insert(account)
  if (!created) throw new Error("Failed to create account")
  return created
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure an official, version-matched adapter is configured
if (!options.adapter?.createAccount) {
  throw new Error("Adapter is missing createAccount implementation")
}

Type guard

function hasAccount(a: unknown): a is NonNullable<AdapterAccount> {
  return !!a && typeof a === "object" && "providerAccountId" in a
}

Try / catch

try {
  await signIn("webauthn", { ... })
} catch (e) {
  if ((e as Error).message === "Error creating or finding account") {
    // adapter returned null — inspect adapter/database logs
  }
}

Prevention

When it happens

Trigger: A custom/broken adapter's createAccount or getAccount implementation returns null or undefined instead of the created account; adapter misconfiguration on the webauthn/callback path where account persistence silently fails.

Common situations: Custom or community adapters that don't honor the Adapter contract; a database outage or constraint violation swallowed by the adapter so it returns null; using an adapter version incompatible with the @auth/core version in use.

Related errors


AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28). Data as JSON: /api/errors/2ec2497157bd6c55. Report an issue: GitHub.