Fauna-backed authentication storage
Persist Auth.js users, accounts, sessions, and verification tokens in Fauna.
Auth.js · Const
FaunaAdapter is Auth.js’s official Fauna adapter. Pass it a Fauna Client and optionally adapter configuration to obtain an Auth.js Adapter.
FaunaAdapter connects Auth.js to Fauna by accepting a Fauna Client and optional adapter configuration, then returning an Auth.js Adapter. Auth.js uses that adapter to persist authentication data; custom collection names can be supplied through the configuration object.
function FaunaAdapter(client, config?): Adapter| Name | Type | Description |
|---|---|---|
client | Client | Fauna client used by the adapter to access the database. |
config | AdapterConfig | Optional adapter configuration, including collection-name overrides. |
Adapter
import NextAuth from "next-auth"
import { Client } from "fauna"
import { FaunaAdapter } from "@auth/fauna-adapter"
const client = new Client({
secret: process.env.AUTH_FAUNA_SECRET,
endpoint: new URL(process.env.AUTH_FAUNA_CLIENT!),
})
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [],
adapter: FaunaAdapter(client),
})Creates a Fauna client from environment variables and supplies it to Auth.js through the adapter.
Persist Auth.js users, accounts, sessions, and verification tokens in Fauna.
Use a non-default Fauna schema naming convention.
Connect a NextAuth.js application to a Fauna database.
FaunaAdapter is a factory function for the official Fauna integration. It receives a Fauna Client and optionally an AdapterConfig, and returns an Auth.js Adapter.
Follow-up: How would you alter the default database naming? Pass a second configuration argument containing collectionNames for user, account, session, and verificationToken.
Create a Fauna Client with the database secret and endpoint, then pass that client to FaunaAdapter in the Auth.js configuration. The adapter is installed from @auth/fauna-adapter, while the Fauna client comes from fauna.
Follow-up: What must be checked when renaming collections? The configured names need to match the actual Fauna database collections.
The optional configuration supports custom collection names. The documented names cover the user, account, session, and verification-token collections.
Follow-up: Why does the name mapping matter? Auth.js adapter operations target those collections, so mismatches prevent the integration from using the intended database collections.
FaunaAccountFaunaSessionFaunaUserFaunaVerificationTokenAdapterConfig