Installation
Setup
1. Define Prisma Schema
Create or update yourprisma/schema.prisma file with the required models:
Important Schema Requirements:
- All
idfields use@default(cuid())for collision-resistant IDs emailandphoneare nullable and unique (users can authenticate with either)- Sessions and Accounts use
onDelete: Cascadeto clean up when users are deleted - The
VerificationTypeenum uses underscores (phone_otp) instead of hyphens - Indexes on
userIdandtokenfields improve query performance
2. Generate Prisma Client
Run the Prisma CLI to generate the client and apply migrations:3. Create Prisma Client Instance
Create a singleton Prisma client instance:lib/prisma.ts
4. Configure Arraf Auth
Use the Prisma adapter in your Arraf Auth configuration:lib/auth.ts
Usage with Next.js
API Reference
prismaAdapter
Creates a database adapter for Prisma.An instance of the Prisma client.
A database adapter that implements all required methods for Arraf Auth.
Schema Field Mapping
The adapter handles automatic conversion between Prisma’s enum format and Arraf Auth’s type format:| Arraf Auth Type | Prisma Enum |
|---|---|
phone-otp | phone_otp |
email-otp | email_otp |
email-verification | email_verification |
password-reset | password_reset |
phone-change | phone_change |
The adapter automatically converts between hyphenated and underscored formats, so you don’t need to worry about this in your application code.
Database Support
The Prisma adapter works with all databases supported by Prisma:- PostgreSQL
- MySQL
- SQLite
- SQL Server
- MongoDB (with some schema adjustments)
- CockroachDB
Migration from Other Adapters
If you’re migrating from another adapter, you can use Prisma’s migration tools:Troubleshooting
Error: PrismaClient is not instantiated
Make sure you’re creating a singleton instance of PrismaClient to avoid connection pool issues:Error: Invalid verificationType
Ensure your Prisma schema includes theVerificationType enum with all required values using underscores.
Next Steps
- Learn about the DatabaseAdapter interface
- Explore session management
- Set up OAuth providers