{"record":{"id":"2ec2497157bd6c55","repo":"nextauthjs/next-auth","slug":"error-creating-or-finding-account","errorCode":null,"errorMessage":"Error creating or finding account","messagePattern":"Error creating or finding account","errorType":"exception","errorClass":"AuthError","httpStatus":null,"severity":"error","filePath":"packages/core/src/lib/actions/callback/index.ts","lineNumber":450,"sourceCode":"      // Check if user is allowed to sign in\n      await handleAuthorized({ user, account }, options)\n\n      // Sign user in, creating them and their account if needed\n      const {\n        user: loggedInUser,\n        isNewUser,\n        session,\n        account: currentAccount,\n      } = await handleLoginOrRegister(\n        sessionStore.value,\n        user,\n        account,\n        options\n      )\n\n      if (!currentAccount) {\n        // This is mostly for type checking. It should never actually happen.\n        throw new AuthError(\"Error creating or finding account\")\n      }\n\n      // Create new authenticator if needed\n      if (authenticator && loggedInUser.id) {\n        await localOptions.adapter.createAuthenticator({\n          ...authenticator,\n          userId: loggedInUser.id,\n        })\n      }\n\n      // Do the session registering dance\n      if (useJwtSession) {\n        const defaultToken = {\n          name: loggedInUser.name,\n          email: loggedInUser.email,\n          picture: loggedInUser.image,\n          sub: loggedInUser.id?.toString(),\n        }","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/core/src/lib/actions/callback/index.ts#L432-L468","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the adapter's createAccount/getAccount return the account object and never resolve null on success","Update or replace the custom adapter with an official one matching your @auth/core major version","Check adapter/database logs for swallowed errors (constraint violations, connection failures) during account creation","Enable Auth.js debug logging (logger debug level) to trace which adapter call returned null"],"exampleFix":"// before (custom adapter)\nasync createAccount(account) { await db.accounts.insert(account) }\n// after\nasync createAccount(account) {\n  const created = await db.accounts.insert(account)\n  if (!created) throw new Error(\"Failed to create account\")\n  return created\n}","handlingStrategy":"try-catch","validationCode":"// ensure an official, version-matched adapter is configured\nif (!options.adapter?.createAccount) {\n  throw new Error(\"Adapter is missing createAccount implementation\")\n}","typeGuard":"function hasAccount(a: unknown): a is NonNullable<AdapterAccount> {\n  return !!a && typeof a === \"object\" && \"providerAccountId\" in a\n}","tryCatchPattern":"try {\n  await signIn(\"webauthn\", { ... })\n} catch (e) {\n  if ((e as Error).message === \"Error creating or finding account\") {\n    // adapter returned null — inspect adapter/database logs\n  }\n}","preventionTips":["Use official adapters matching your @auth/core major version","Unit-test custom adapters' createAccount/getAccount return values","Enable debug logging to trace adapter calls","Alert on database constraint/connection errors during sign-in"],"tags":["adapter","webauthn","account-linking"],"backgroundTag":"adapter-account-null","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}