Skip to content
Migrating from NextAuth.js v4? Read our migration guide.
Getting Started
Adapters
Drizzle

Drizzle ORM Adapter

Resources

Setup

Installation

npm install drizzle-orm @auth/drizzle-adapter
npm install drizzle-kit --save-dev

Environment Variables

DRIZZLE_DATABASE_URL=postgres://postgres:adminadmin@0.0.0.0:5432/db

Configuration

Follow the Drizzle documentation for PostgreSQL setup, MySQL setup and SQLite setup.

./auth.ts
import NextAuth from "next-auth"
import { DrizzleAdapter } from "@auth/drizzle-adapter"
import { db } from "./db.ts"
 
export const { handlers, auth, signIn, signOut } = NextAuth({
  adapter: DrizzleAdapter(db),
  providers: [],
})

Apply one of the below schema’s to your database to setup the required tables.

Migrating your database

With your schema now described in your code, you’ll need to migrate your database to your schema.

For full documentation on how to run migrations with Drizzle, visit the Drizzle documentation or check how to apply changes directly to the database with push command.

Auth.js © Balázs Orbán and Team - 2024