Firestore-backed authentication
Persist Auth.js users, accounts, sessions, and verification data in Firestore.
Auth.js · Const
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.
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.
FirestoreAdapter(config?: FirebaseAdapterConfig): Adapter| Name | Type | Description |
|---|---|---|
config | FirebaseAdapterConfig | Optional Firebase adapter configuration, including collection-name overrides and credential settings. |
An Auth.js adapter object for Firestore.
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.
Persist Auth.js users, accounts, sessions, and verification data in Firestore.
Use a Firebase service account to authenticate server-side Firestore access.
Keep Auth.js data separate from application data by assigning custom collection names.
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.
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.
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.
FirestoreAdapterFirebaseAdapterConfiginitFirestorefirebase-adminFirestore