Connect Auth.js to a database or ORM
The application needs persistent users, linked provider accounts, or database-backed sessions.
Auth.js · Pipe
An Auth.js adapter is the data-access layer that normalizes user, account, session, and related authentication persistence behind a common interface. Pass an adapter object, or configure one through an adapter factory, in Auth.js options.
An adapter connects Auth.js to a data source through methods that implement the common user, account, session, and passwordless-authentication operations. Supply either an adapter object directly or invoke an adapter factory with its configuration, then pass the result as the adapter option.
NextAuth({ adapter: MyAdapter })| Name | Type | Description |
|---|---|---|
adapter | Adapter | AdapterFactoryResult | Adapter implementation or an adapter factory result, supplied through Auth.js configuration. |
import NextAuth from "next-auth"
import { MyAdapter } from "./my-adapter"
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [],
adapter: MyAdapter,
})Pass the adapter object to Auth.js through the adapter option.
The application needs persistent users, linked provider accounts, or database-backed sessions.
The chosen database or service has no official Auth.js integration.
The application uses passwordless authentication and must persist its authentication records.
An adapter is an object whose methods read and write a data source using interfaces Auth.js understands. It lets Auth.js create, update, and delete users, link accounts, manage sessions, and support passwordless authentication.
Follow-up: How can an application use a data solution without an official adapter? Implement an Auth.js-compatible adapter, commonly as a factory that receives a database or ORM client and returns the required methods.
Configure it with the adapter option in Auth.js. The value can be an adapter object directly, or the result of calling an adapter factory with configuration.
Follow-up: Why might the factory form be useful? It allows the adapter to capture a client or other integration-specific configuration while exposing the standard adapter interface.
Adapters normalize different data layers behind common interfaces, so Auth.js can work with databases, ORMs, backend APIs, or HTTP clients. The adapter methods perform operations such as user management, account linking, session handling, and passwordless login support.
Follow-up: What should be implemented first in a minimal adapter? Implement only the methods required by the authentication flows the application actually uses, while keeping their behavior compatible with the Adapter interface.
AdapterAdapterAccountAdapterSessionAdapterAuthenticatorOfficial database adapters