Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Auth.js · Const

FirebaseAdapter

FirebaseAdapter is Auth.js’s official Firestore adapter, built on the Firebase Admin SDK. Use it as the adapter in Auth.js configuration to persist authentication data in Firestore.

How it works

FirebaseAdapter is the Auth.js Firestore adapter factory. Calling it creates an adapter that Auth.js can use to persist authentication data in Firestore through the Firebase Admin SDK; optional configuration can customize collections or supply credentials.

Syntax

FirestoreAdapter(config?: FirebaseAdapterConfig): Adapter

Parameters

NameTypeDescription
configFirebaseAdapterConfigOptional Firebase adapter configuration, including collection-name overrides and credential settings.

Returns

An Auth.js adapter object for Firestore.

Key points

  • It connects Auth.js to Firestore and relies on the Firebase Admin SDK.
  • Install both the adapter package and Firebase Admin SDK before configuring it.
  • Pass a collections option to replace default collection names, including the users collection.
  • With the documented credential-file environment variable configured, the adapter discovers that credential automatically.
  • Environment-based credentials can use the AUTH_FIREBASE_PROJECT_ID, AUTH_FIREBASE_CLIENT_EMAIL, and AUTH_FIREBASE_PRIVATE_KEY variables.

Common mistakes

  • Do not commit a downloaded Firebase service-account key; keep the credential file out of version control.
  • When GOOGLE_APPLICATION_CREDENTIALS points to the service-account file, extra adapter authentication configuration is unnecessary.

Example: Configure Firestore persistence

import NextAuth from "next-auth"
import { FirestoreAdapter } from "@auth/firebase-adapter"

export const { handlers, auth, signIn, signOut } = NextAuth({
  providers: [],
  adapter: FirestoreAdapter(),
})

This configures Auth.js to use Firestore through the Firebase adapter.

When to use it

Firestore-backed authentication

Persist Auth.js users, accounts, sessions, and verification data in Firestore.

Admin SDK credential setup

Use a Firebase service account to authenticate server-side Firestore access.

Collection customization

Keep Auth.js data separate from application data by assigning custom collection names.

Interview questions

QWhat does FirebaseAdapter connect Auth.js to?

FirebaseAdapter is the Firestore adapter supplied by @auth/firebase-adapter. It uses the Firebase Admin SDK so Auth.js can store its authentication records in Firestore.

Follow-up: How can credentials be provided without a key file? Use the documented Firebase environment variables and pass a credential created with cert in the adapter configuration.

QHow is the adapter configured?

Call FirestoreAdapter() in the Auth.js configuration's adapter field. The package and firebase-admin must be installed first.

Follow-up: How would you customize storage names? Pass a collections configuration object, such as a custom users collection name.

QCan Firestore collection names be customized?

The adapter defaults to the standard collection names, but its configuration can override them. For example, the users collection can be changed through collections.users.

Follow-up: What operational concern remains when using a service-account file? Store it securely and ensure it is excluded from version control.

  • FirestoreAdapter
  • FirebaseAdapterConfig
  • initFirestore
  • firebase-admin
  • Firestore

Source: auth/firebase-adapter. Checked 2026-10-15.