Persist authentication data
An Auth.js application needs persistent users, accounts, and sessions in a Sequelize-supported database.
Auth.js · Const
SequelizeAdapter connects Auth.js to a Sequelize database client and returns an Auth.js Adapter. Install the adapter, Sequelize, and the database driver, then provide the configured client to Auth.js.
SequelizeAdapter connects Auth.js to a Sequelize database client. Calling it returns an Auth.js Adapter that supplies persistence for users, accounts, sessions, and related authentication data through Sequelize models.
SequelizeAdapter(client, options?)| Name | Type | Description |
|---|---|---|
client | Sequelize | Configured Sequelize database client used by the adapter. |
options | SequelizeAdapterOptions | Optional Sequelize adapter configuration. |
Adapter
import NextAuth from "next-auth"
import SequelizeAdapter from "@auth/sequelize-adapter"
import { Sequelize } from "sequelize"
const sequelize = new Sequelize(process.env.DATABASE_URL!)
export const { handlers, auth } = NextAuth({
providers: [],
adapter: SequelizeAdapter(sequelize),
})Creates a Sequelize client from the database URL and supplies the resulting adapter to Auth.js.
An Auth.js application needs persistent users, accounts, and sessions in a Sequelize-supported database.
A project already uses Sequelize and wants Auth.js to reuse its configured database connection.
A team needs Auth.js tables managed predictably across deployment environments.
SequelizeAdapter is a factory that accepts a Sequelize client and returns an Auth.js Adapter. Auth.js then uses that adapter to persist authentication data through Sequelize.
Follow-up: What must be supplied to the factory? A configured Sequelize instance, typically initialized with the application database connection string.
Its required parameter is client, whose type is Sequelize. An optional options parameter can customize adapter behavior.
Follow-up: Why pass a client instead of a connection string? The adapter relies on the already configured Sequelize instance and its database dialect, connection, and models.
The adapter package does not create database tables by default. Production deployments should create the required schema with migrations; development can use sequelize.sync().
Follow-up: What is the tradeoff of sequelize.sync()? It is convenient for development, but migrations provide controlled and repeatable schema changes for production.
@auth/sequelize-adapterSequelizeAdapterOptionsAdapterSequelizeAccountSessionUserVerificationToken