{"record":{"id":"8ec1c800c9059a57","repo":"nextauthjs/next-auth","slug":"firebaseadapter-value-for-key-key-is-undefin","errorCode":null,"errorMessage":"FirebaseAdapter: value for key \"${key}\" is undefined","messagePattern":"FirebaseAdapter: value for key \"(.+?)\" is undefined","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/adapter-firebase/src/index.ts","lineNumber":293,"sourceCode":"}\n\nfunction getConverter<Document extends Record<string, any>>(options: {\n  excludeId?: boolean\n  preferSnakeCase?: boolean\n}): FirebaseFirestore.FirestoreDataConverter<Document> {\n  const mapper = mapFieldsFactory(options?.preferSnakeCase)\n\n  return {\n    toFirestore(object) {\n      const document: Record<string, unknown> = {}\n\n      for (const key in object) {\n        if (key === \"id\") continue\n        const value = object[key]\n        if (value !== undefined) {\n          document[mapper.toDb(key)] = value\n        } else {\n          console.warn(`FirebaseAdapter: value for key \"${key}\" is undefined`)\n        }\n      }\n\n      return document\n    },\n\n    fromFirestore(\n      snapshot: FirebaseFirestore.QueryDocumentSnapshot<Document>\n    ): Document {\n      const document = snapshot.data()! // we can guarantee it exists\n\n      const object: Record<string, unknown> = {}\n\n      if (!options?.excludeId) {\n        object.id = snapshot.id\n      }\n\n      for (const key in document) {","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/adapter-firebase/src/index.ts#L275-L311","documentation":"The Firebase adapter's toFirestore helper skips undefined values (Firestore cannot store undefined) and warns for each key whose value is undefined, because such data would be silently dropped from the document. It signals that the object being persisted contains a field the adapter expects to be defined. The write proceeds but the undefined key is omitted from the Firestore document.","triggerScenarios":"Calling any adapter method (createUser, getUser, updateUser, createSession, etc.) whose model object contains a property (other than `id`) set to undefined, e.g. a missing emailVerified, sessionToken, or a custom field, which triggers the else branch in toFirestore.","commonSituations":"Custom user models with optional fields mapped through the adapter; passing partially built objects (e.g. { user: { name: undefined } }) from JWT/callbacks; mismatch between the NextAuth model shape and the Firestore collection mapper.","solutions":["Ensure all required fields in the object passed to the adapter are defined before calling the adapter method (default them in events.signIn / jwt callbacks)","Add a custom mapper so optional fields map to null instead of undefined (Firestore supports null)","Update to the latest adapter version, as handling of undefined fields has changed over releases"],"exampleFix":"// before\nawait adapter.createUser({ name: user.name, emailVerified: user.emailVerified }) // emailVerified undefined\n// after\nawait adapter.createUser({ name: user.name ?? null, emailVerified: user.emailVerified ?? new Date(0) })","handlingStrategy":"validation","validationCode":"function assertFirestoreReady(obj: Record<string, unknown>, skip = [\"id\"]) {\n  const bad = Object.entries(obj)\n    .filter(([k, v]) => !skip.includes(k) && v === undefined)\n    .map(([k]) => k)\n  if (bad.length) throw new Error(`Undefined adapter fields: ${bad.join(\", \")}`)\n}","typeGuard":"function hasNoUndefined<T extends Record<string, unknown>>(o: T): boolean {\n  return Object.entries(o).every(([k, v]) => k === \"id\" || v !== undefined)\n}","tryCatchPattern":null,"preventionTips":["Default optional fields to null (not undefined) in jwt/session/signIn callbacks","Coerce user/model objects before passing them to adapter methods","Align custom Firestore mappers with the NextAuth model shape","Add a dev-time assertion that adapter inputs contain no undefined fields"],"tags":["firebase","firestore","undefined-value","data-mapping"],"backgroundTag":"undefined-value-in-firestore-document","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}