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

Auth.js · Pipe

adapter

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.

How it works

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.

Syntax

NextAuth({ adapter: MyAdapter })

Parameters

NameTypeDescription
adapterAdapter | AdapterFactoryResultAdapter implementation or an adapter factory result, supplied through Auth.js configuration.

Key points

  • An adapter is a method-bearing object that reads and writes the application's authentication data source.
  • The common interface lets Auth.js work across different data-layer technologies.
  • Its methods cover the persistence work required by authentication flows.
  • User lifecycle operations are part of the adapter contract.
  • Adapters manage associations between provider accounts and users.
  • Session persistence and retrieval can be delegated to the adapter.

Common mistakes

  • Check the official adapter list before building a custom adapter; an existing integration may already meet your needs.
  • Creating a custom adapter is usually unnecessary when your database already has an official adapter.

Example: Configure a custom adapter

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.

When to use it

Connect Auth.js to a database or ORM

The application needs persistent users, linked provider accounts, or database-backed sessions.

Integrate a custom data source

The chosen database or service has no official Auth.js integration.

Support passwordless flows

The application uses passwordless authentication and must persist its authentication records.

Interview questions

QWhat problem does an Auth.js adapter solve?

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.

QHow is an adapter supplied to Auth.js?

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.

QWhy can Auth.js support different kinds of data layers?

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.

  • Adapter
  • AdapterAccount
  • AdapterSession
  • AdapterAuthenticator
  • Official database adapters

Source: Adapters - Auth.js. Checked 2026-10-15.