nextauthjs/next-auth · warning

FirebaseAdapter: value for key "${key}" is undefined

Error message

FirebaseAdapter: value for key "${key}" is undefined

What it means

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.

Source

Thrown at packages/adapter-firebase/src/index.ts:293

}

function getConverter<Document extends Record<string, any>>(options: {
  excludeId?: boolean
  preferSnakeCase?: boolean
}): FirebaseFirestore.FirestoreDataConverter<Document> {
  const mapper = mapFieldsFactory(options?.preferSnakeCase)

  return {
    toFirestore(object) {
      const document: Record<string, unknown> = {}

      for (const key in object) {
        if (key === "id") continue
        const value = object[key]
        if (value !== undefined) {
          document[mapper.toDb(key)] = value
        } else {
          console.warn(`FirebaseAdapter: value for key "${key}" is undefined`)
        }
      }

      return document
    },

    fromFirestore(
      snapshot: FirebaseFirestore.QueryDocumentSnapshot<Document>
    ): Document {
      const document = snapshot.data()! // we can guarantee it exists

      const object: Record<string, unknown> = {}

      if (!options?.excludeId) {
        object.id = snapshot.id
      }

      for (const key in document) {

View on GitHub (pinned to a1a16a5a77)

Solutions

  1. 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)
  2. Add a custom mapper so optional fields map to null instead of undefined (Firestore supports null)
  3. Update to the latest adapter version, as handling of undefined fields has changed over releases

Example fix

// before
await adapter.createUser({ name: user.name, emailVerified: user.emailVerified }) // emailVerified undefined
// after
await adapter.createUser({ name: user.name ?? null, emailVerified: user.emailVerified ?? new Date(0) })
Defensive patterns

Strategy: validation

Validate before calling

function assertFirestoreReady(obj: Record<string, unknown>, skip = ["id"]) {
  const bad = Object.entries(obj)
    .filter(([k, v]) => !skip.includes(k) && v === undefined)
    .map(([k]) => k)
  if (bad.length) throw new Error(`Undefined adapter fields: ${bad.join(", ")}`)
}

Type guard

function hasNoUndefined<T extends Record<string, unknown>>(o: T): boolean {
  return Object.entries(o).every(([k, v]) => k === "id" || v !== undefined)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28). Data as JSON: /api/errors/8ec1c800c9059a57. Report an issue: GitHub.