Function: createPrismaAdapter()
function createPrismaAdapter(options): PasswordAdapter
Creates a password-capable Auth.js adapter backed by Prisma. Wraps the
official @auth/prisma-adapter and layers on password helpers.
⚠️ Security:
- Passwords are hashed by the provider before storage; plaintext never touches the DB.
- Verification tokens (handled by the base adapter) are hashed with SHA-256.
- Email lookups are case-insensitive; prefer Postgres
@db.Citextor database collations for enforcement.
Performance:
- Each password operation performs 1–2 queries; ensure
userIdandemailcolumns are indexed. findUserIdByEmailperforms two lookups (user + password models). Optimize with database indexes.
Edge cases:
- Requires
@auth/prisma-adapterand@prisma/client. Install both:npm i @auth/prisma-adapter @prisma/client. - Password model must include
id,userId,email,hash,createdAt,updatedAtcolumns. - Concurrent password updates can race; wrap in application-level locks if necessary.
deleteUseris overridden to remove password rows; omitting this would leave orphaned sensitive data.findUserIdByEmailfalls back to password rows for legacy schemas withoutuser.email.
Parameters
| Parameter | Type |
|---|---|
options | PrismaAdapterOptions |
Returns
PasswordAdapter implementing Auth.js contract plus password helpers (createUserPassword, getUserPassword, deleteUserPassword, resetUserPassword, findUserIdByEmail).
Throws
If the Prisma client or password delegate is missing.
Throws
If @auth/prisma-adapter is not installed.
Examples
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const adapter = createPrismaAdapter({ client: prisma, secret: process.env.AUTH_SECRET! })
const adapter = createPrismaAdapter({
client: prisma,
secret: process.env.AUTH_SECRET!,
models: { password: 'userPassword' }
})
export default {
adapter: createPrismaAdapter({ client: prisma, secret: process.env.AUTH_SECRET! }),
providers: [...]
}
try {
createPrismaAdapter({ client: prisma, secret: process.env.AUTH_SECRET! })
} catch (error) {
if (String(error).includes('prisma-adapter')) {
console.error('Install @auth/prisma-adapter before continuing')
}
}
See
- PasswordAdapter in
src/builtins/email-password/types.ts - @auth/prisma-adapter for the base adapter implementation.
- listPrismaUserIds and listPrismaUsers for pagination helpers.