Installation
1
Install Prisma and the Prisma Client
- npm
- pnpm
- yarn
- bun
2
Configure the adapter
Import
prismaAdapter from better-auth/adapters/prisma and pass a PrismaClient instance:auth.ts
Configuration options
TheprismaAdapter function accepts a PrismaClient instance and a config object:
Prisma schema
The Better Auth CLI generates the required Prisma schema models based on your configuration and plugins.Core schema
The schema below is the baseline required by Better Auth. The CLI generates this for you, including@relation directives needed for experimental joins.
schema.prisma
The
@@map directives keep Prisma model names in PascalCase while mapping to the lowercase table names Better Auth expects.Applying migrations
After generating or editing your schema, run Prisma Migrate to apply the changes:Experimental joins
Enabling joins allows Better Auth to fetch related data in a single query instead of multiple round-trips. Endpoints such as/get-session and /get-full-organization see 2-3x latency improvements with high-latency databases.
auth.ts