{"record":{"id":"29571c9c76bad5ee","repo":"nextauthjs/next-auth","slug":"user-not-found-29571c","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapter-mikro-orm/src/index.ts","lineNumber":123,"sourceCode":"      if (!user) return null\n\n      return wrap(user).toObject()\n    },\n    async getUserByAccount(provider_providerAccountId) {\n      const em = await getEM()\n      const account = await em.findOne(AccountModel, {\n        ...provider_providerAccountId,\n      })\n      if (!account) return null\n      const user = await em.findOne(UserModel, { id: account.userId })\n      if (!user) return null\n\n      return wrap(user).toObject()\n    },\n    async updateUser(data) {\n      const em = await getEM()\n      const user = await em.findOne(UserModel, { id: data.id })\n      if (!user) throw new Error(\"User not found\")\n      // `mergeObjects` (v5) was renamed to `mergeObjectProperties` (v6)\n      wrap(user).assign(data, {\n        mergeObjectProperties: true,\n        ...{ mergeObjects: true },\n      })\n      await em.persistAndFlush(user)\n\n      return wrap(user).toObject()\n    },\n    async deleteUser(id) {\n      const em = await getEM()\n      const user = await em.findOne(UserModel, { id })\n      if (!user) return null\n      await em.removeAndFlush(user)\n\n      return wrap(user).toObject()\n    },\n    // @ts-expect-error","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/adapter-mikro-orm/src/index.ts#L105-L141","documentation":"MikroORM adapter's updateUser first fetches the user entity by data.id; if no row matches, it throws 'User not found' instead of silently failing. Unlike some adapters that upsert, this one requires the user to already exist for updateUser.","triggerScenarios":"Calling updateUser with an id that has no User row, a stale id from a deleted user, or id being undefined/NaN due to bad mapping between Auth.js user.id and the ORM primary key (e.g., numeric id vs string).","commonSituations":"Auth.js updating a user whose row was manually deleted from the DB; switching the User primary key type (autoincrement int vs uuid) without migrating; passing an email instead of id by mistake; database reset between environments.","solutions":["Confirm a user row with that exact id exists (check type: number vs string id)","Create the user first ( createUser) if updateUser is called for a possibly-new record, or wrap in existence check","Fix id mapping between Auth.js identity and the User entity primary key","Restore/check the database for deleted users and clear stale session cookies referencing them"],"exampleFix":"// before\nawait adapter.updateUser({ id: 42, name: 'New' })\n// after\nconst existing = await adapter.getUser(42)\nif (existing) await adapter.updateUser({ id: 42, name: 'New' })","handlingStrategy":"try-catch","validationCode":"const user = await adapter.getUser(data.id)\nif (!user) throw new Error(`Cannot update missing user ${data.id}`)","typeGuard":"function hasId(v: unknown): v is { id: string | number } {\n  return typeof v === 'object' && v !== null && 'id' in v && v.id != null\n}","tryCatchPattern":"try {\n  await adapter.updateUser(data)\n} catch (e) {\n  if ((e as Error).message === 'User not found') {\n    await adapter.createUser(data) // or log and skip\n  } else throw e\n}","preventionTips":["Verify user id exists (and its type) before updateUser","Keep user rows and auth cookies in sync (no orphan cookies after DB resets)","Use the same primary key type across migrations","Wrap update flows in existence checks"],"tags":["mikro-orm","database","user-not-found","auth"],"backgroundTag":"record-not-found","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}