Database-backed authentication
Persist users, accounts, sessions, and verification data through Prisma in an Auth.js application.
Auth.js · Function
PrismaAdapter connects Auth.js to a Prisma-backed database. Give it an initialized Prisma client and place the returned Adapter in Auth.js configuration.
PrismaAdapter receives a Prisma client and converts it into an Auth.js database adapter. Pass the returned adapter to Auth.js configuration so authentication data can be stored and retrieved through Prisma.
function PrismaAdapter(prisma): Adapter| Name | Type | Description |
|---|---|---|
prisma | PrismaClient | DynamicClientExtensionThis | Initialized Prisma client used by the adapter to access the database. |
Adapter
import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { prisma } from "@/prisma"
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: PrismaAdapter(prisma),
providers: [],
})Creates an Auth.js configuration that persists authentication data through the Prisma client.
Persist users, accounts, sessions, and verification data through Prisma in an Auth.js application.
Reuse a Prisma client configured for the application's database as Auth.js's persistence layer.
Add the adapter to framework integrations such as NextAuth while keeping authentication configuration centralized.
PrismaAdapter is the official Prisma database adapter for Auth.js. It accepts a Prisma client and returns an Auth.js Adapter that can be supplied in the Auth.js configuration.
Follow-up: How would you use it in NextAuth? Instantiate PrismaClient, call PrismaAdapter(prisma), and assign the result to the adapter option.
The function parameter is a PrismaClient or compatible dynamic client extension. Its return type is Adapter, which is the interface Auth.js uses for database persistence.
Follow-up: Why is the returned type useful? It lets Auth.js consume the adapter through a standard interface independent of the underlying database implementation.
Install @auth/prisma-adapter together with @prisma/client, then import PrismaAdapter and pass it the initialized Prisma client. The resulting adapter is configured alongside providers.
Follow-up: What deployment concern can arise? Prisma-based configuration may be edge-incompatible, so the edge instance should omit the adapter.
AdapterPrismaClient@auth/prisma-adapter@prisma/clientNextAuth