{"record":{"id":"46900836a7155bd1","repo":"nextauthjs/next-auth","slug":"error-updating-user-cannot-get-user-after-updatin","errorCode":null,"errorMessage":"Error updating user: Cannot get user after updating.","messagePattern":"Error updating user: Cannot get user after updating\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapter-d1/src/index.ts","lineNumber":213,"sourceCode":"        user.id,\n      ])\n      if (params) {\n        // copy any properties not in the update into the existing one and use that for bind params\n        // covers the scenario where the user arg doesnt have all of the current users properties\n        Object.assign(params, user)\n        const res = await updateRecord(db, UPDATE_USER_BY_ID_SQL, [\n          params.name,\n          params.email,\n          params.emailVerified?.toISOString(),\n          params.image,\n          params.id,\n        ])\n        if (res.success) {\n          const user = await getRecord<AdapterUser>(db, GET_USER_BY_ID_SQL, [\n            params.id,\n          ])\n          if (user) return user\n          throw new Error(\n            \"Error updating user: Cannot get user after updating.\"\n          )\n        }\n      }\n      throw new Error(\"Error updating user: Failed to run the update SQL.\")\n    },\n    async deleteUser(userId) {\n      // miniflare doesn't support batch operations or multiline sql statements\n      await deleteRecord(db, DELETE_ACCOUNT_BY_USER_ID_SQL, [userId])\n      await deleteRecord(db, DELETE_SESSION_BY_USER_ID_SQL, [userId])\n      await deleteRecord(db, DELETE_USER_SQL, [userId])\n      return null\n    },\n    async linkAccount(a) {\n      // convert user_id to userId and provider_account_id to providerAccountId\n      const id = crypto.randomUUID()\n      const createBindings = [\n        id,","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/adapter-d1/src/index.ts#L195-L231","documentation":"updateUser runs the UPDATE SQL, and when it reports success it immediately re-selects the user by id; if that SELECT returns nothing the adapter throws this error. It indicates the update claimed success but the row cannot be read back, so the adapter will not fabricate a user object.","triggerScenarios":"adapter.updateUser({ id, ... }) where res.success is true but GET_USER_BY_ID_SQL finds no row for params.id — e.g. updating a user id that does not exist in the users table, or schema/column mismatches making the read fail.","commonSituations":"Stale user id from a deleted row, updating a user created outside this adapter with a different id format, custom table schema, or D1 binding pointing at a different database than the one that holds the user.","solutions":["Confirm a user with that id actually exists (SELECT it manually or via getUser(id)) before updating.","Verify the D1 binding points at the database containing the users table.","Check that the users table schema matches the adapter's expected SQL (column names, primary key on id).","Upgrade the adapter package to get the latest D1 batch/SQL fixes."],"exampleFix":"// before\nawait adapter.updateUser({ id: maybeId, email: newEmail })\n// after\nconst existing = await adapter.getUser(maybeId)\nif (!existing) throw new Error(`No user with id ${maybeId}`)\nawait adapter.updateUser({ id: maybeId, email: newEmail })","handlingStrategy":"validation","validationCode":"const user = await adapter.getUser(id)\nif (!user) throw new Error(`Cannot update: no user with id ${id}`)","typeGuard":"function hasUserId(u: Partial<AdapterUser>): u is Partial<AdapterUser> & Pick<AdapterUser, 'id'> {\n  return typeof u.id === 'string' && u.id.length > 0\n}","tryCatchPattern":"try {\n  const updated = await adapter.updateUser({ id, ...changes })\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Cannot get user after updating')) {\n    // re-fetch via getUser(id); if missing, the row was deleted concurrently\n  }\n  throw e\n}","preventionTips":["Always verify the user exists with getUser(id) before updating","Only pass AdapterUser fields (id, email, emailVerified, name, image) to updateUser","Confirm your D1 binding points at the intended database","Pin/update the adapter version to avoid known D1 batch bugs"],"tags":["database","d1","cloudflare","update"],"backgroundTag":"record-not-found-after-write","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}