{"record":{"id":"4d7d7b8d330613e4","repo":"nextauthjs/next-auth","slug":"createsession-failed-to-fetch-created-session","errorCode":null,"errorMessage":"[createSession] Failed to fetch created session","messagePattern":"\\[createSession\\] Failed to fetch created session","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapter-firebase/src/index.ts","lineNumber":178,"sourceCode":"      return account ?? null\n    },\n\n    async unlinkAccount({ provider, providerAccountId }) {\n      await deleteDocs(\n        C.accounts\n          .where(\"provider\", \"==\", provider)\n          .where(mapper.toDb(\"providerAccountId\"), \"==\", providerAccountId)\n          .limit(1)\n      )\n    },\n\n    async createSession(sessionInit) {\n      const ref = await C.sessions.add(sessionInit)\n      const session = await ref.get().then((doc) => doc.data())\n\n      if (session) return session ?? null\n\n      throw new Error(\"[createSession] Failed to fetch created session\")\n    },\n\n    async getSessionAndUser(sessionToken) {\n      const session = await getOneDoc(\n        C.sessions.where(mapper.toDb(\"sessionToken\"), \"==\", sessionToken)\n      )\n      if (!session) return null\n\n      const user = await getDoc(C.users.doc(session.userId))\n      if (!user) return null\n\n      return { session, user }\n    },\n\n    async updateSession(partialSession) {\n      const sessionId = await db.runTransaction(async (transaction) => {\n        const sessionSnapshot = (\n          await transaction.get(","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/adapter-firebase/src/index.ts#L160-L196","documentation":"The Firebase adapter's createSession adds a session document, then reads it back via ref.get(). If the resulting data is falsy it throws '[createSession] Failed to fetch created session'. The adapter insists on returning a fully materialized session, so a failed round-trip aborts sign-in.","triggerScenarios":"C.sessions.add(sessionInit) succeeds but the immediate get() returns empty data — security rules denying the read, sessionInit producing a doc with no fields, or a custom get/then helper failing to unwrap doc.data().","commonSituations":"Firestore rules that allow create but not read on the sessions collection (common with least-privilege configs); emulator/prod project mismatch; session payload mappers dropping all fields so data() comes back empty.","solutions":["Check Firestore security rules allow reading documents the adapter just created in the sessions collection.","Log sessionInit and verify the mapper produces non-empty fields before add().","Confirm the adapter's Firestore instance points at the same project/database as the write.","If a trigger cleans up session docs on create, remove or scope it."],"exampleFix":"// before\nconst ref = await C.sessions.add(sessionInit)\nconst session = await ref.get().then((doc) => doc.data())\nif (session) return session ?? null\nthrow new Error('[createSession] Failed to fetch created session')\n// after\nconst ref = await C.sessions.add(sessionInit)\nconst snap = await ref.get()\nif (!snap.exists) throw new Error('[createSession] Failed to fetch created session')\nreturn { ...sessionInit, ...snap.data() }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function hasSessionData(d: Record<string, unknown> | undefined): d is Record<string, unknown> {\n  return !!d && Object.keys(d).length > 0\n}","tryCatchPattern":"try {\n  const session = await adapter.createSession(sessionInit)\n  return session\n} catch (e) {\n  if ((e as Error).message.includes('Failed to fetch created session')) {\n    console.error('Session create/read round-trip failed; check Firestore rules on sessions', e)\n    throw e\n  }\n  throw e\n}","preventionTips":["Allow read access to freshly created session docs in Firestore rules.","Ensure the session mapper writes non-empty fields so data() is populated.","Keep emulator/production project configuration consistent for sign-in flows."],"tags":["firebase","firestore","database","session","not-found"],"backgroundTag":"record-not-found","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}