{"record":{"id":"24049daba511538a","repo":"nextauthjs/next-auth","slug":"user-id-is-required","errorCode":null,"errorMessage":"User id is required","messagePattern":"User id is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapter-surrealdb/src/index.ts","lineNumber":246,"sourceCode":"      provider,\n    }: Pick<AdapterAccount, \"provider\" | \"providerAccountId\">) {\n      const surreal = await client\n      try {\n        const [accounts] = await surreal.query<[AccountDoc<UserDoc>[]]>(\n          `SELECT userId FROM account WHERE providerAccountId = $providerAccountId AND provider = $provider FETCH userId`,\n          {\n            providerAccountId,\n            provider,\n          }\n        )\n        const user = accounts.at(0)?.userId\n        if (user) return docToUser(user)\n      } catch {}\n      return null\n    },\n    async updateUser(user: Partial<AdapterUser>) {\n      try {\n        if (!user.id) throw new Error(\"User id is required\")\n        const surreal = await client\n        const doc: Partial<UserDoc> | null = removeUndefinedFields(\n          userToDoc({\n            ...user,\n            id: undefined,\n          })\n        )\n        if (doc) {\n          const updatedUser = await surreal.merge<UserDoc, Partial<UserDoc>>(\n            new RecordId(\"user\", user.id),\n            doc\n          )\n          if (updatedUser) {\n            return docToUser(updatedUser)\n          }\n        }\n      } catch {}\n      throw new Error(\"User not updated\")","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/adapter-surrealdb/src/index.ts#L228-L264","documentation":"The SurrealDB adapter's updateUser() requires the partial user object to carry an `id` so it knows which user document to update. If `user.id` is undefined or an empty value, the adapter throws immediately before touching the database. This guards against SurrealDB silently updating nothing (or the wrong record) when the identifier is missing.","triggerScenarios":"Calling adapter.updateUser({ name, email }) without an `id` field; building the partial from a form/DTO that drops the id; spreading an object where id was explicitly set to undefined; calling it from custom code rather than through Auth.js flow (which always supplies id).","commonSituations":"Custom auth scripts that update a user's profile; migrating from another adapter whose updateUser tolerated missing ids; destructuring a session user into a new object and forgetting to copy `id`.","solutions":["Ensure the object passed to updateUser includes a valid `user.id` (the adapter user id, not the raw DB record id)","Check that id is not being stripped by a sanitizer, DTO mapper, or removeUndefinedFields-like transform before the call","If updating by email instead, first fetch the user via getUserByEmail and pass the returned full user object","Log the object right before the call to confirm `id` is present and non-empty"],"exampleFix":"// before\nawait adapter.updateUser({ name: 'New Name' })\n// after\nconst user = await adapter.getUserByEmail('me@example.com')\nawait adapter.updateUser({ ...user, name: 'New Name' })","handlingStrategy":"validation","validationCode":"if (!user?.id) throw new Error('updateUser requires a user with an id')\nawait adapter.updateUser(user)","typeGuard":"function hasId(u: Partial<AdapterUser>): u is Partial<AdapterUser> & { id: string } {\n  return typeof u.id === 'string' && u.id.length > 0\n}","tryCatchPattern":"try {\n  const updated = await adapter.updateUser(user)\n} catch (e) {\n  if (e.message === 'User id is required') {\n    // fix payload: fetch full user first\n  }\n}","preventionTips":["Always fetch the full user via getUser/getUserByEmail before partial updates","Never strip `id` with DTO mappers or spread-based sanitizers before adapter calls","Add a unit test asserting updateUser rejects/accepts based on id presence"],"tags":["adapter","validation","surrealdb"],"backgroundTag":"missing-required-identifier","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}