@glinr/theauth-prisma adapter lets you query the core theAuth tables through your existing PrismaClient, without using Drizzle in your own code.
The Prisma adapter is a standalone query layer. It does not replace or wrap
the core theAuth instance. Use it to read and write theAuth data from
the parts of your codebase that already work with Prisma.
When to use it
- You have an existing Prisma project and want to avoid running two ORM clients.
- You need to query theAuth tables inside Prisma transactions that span your own models.
- You prefer generated Prisma types over Drizzle’s schema for editor autocomplete.
- Your team finds Prisma’s DSL easier to maintain than raw SQL DDL.
Installation
@glinr/theauth and @prisma/client (5.0 or later) as peer dependencies. The adapter code itself does not import the core package at runtime.
Setup
1
Add the theAuth models to your Prisma schema
Copy the models fromnode_modules/@glinr/theauth-prisma/src/schema.prisma into your prisma/schema.prisma, or use it as a reference to add only the tables you need. The schema declares no relations, so add relations and onDelete rules yourself if you want them.The schema targets Postgres by default. Switch the datasource provider to sqlite or mysql as appropriate.Usage
Agent operations
User operations
Session management
Audit log queries
Permissions
Transactions
The adapter wraps Prisma’s$transaction to let you compose theAuth operations with your own Prisma queries:
Trust scores
Approval requests
requiredApprovals (null or 1 means a single approver) and count each approver with castApprovalVote, which keeps the same single vote guarantee as the core library:
TheAuthApprovalVote stops one approver being counted twice when two calls race. The request flips to approved with one updateMany on status = pending and an unexpired expiresAt, so only one caller completes the quorum, and the first requiredApprovals votes are the ones reported. listApprovalVotes(approvalId) returns who has approved. A denial is a plain updateApprovalRequest with status: 'denied'. If you already have a database from the core migrations, the new model maps onto migration 0013 (required_approvals column and theauth_approval_votes table), so no extra migration is needed. The concurrency tests run against a real SQLite Prisma 7 client with the better-sqlite3 driver adapter.
Indexes
The referenceschema.prisma declares the hot path indexes from core migration 0014 with @@index(..., map: "..."), using the same names as the SQL migration. If you wrote your own models, add them, or prisma migrate dev will not create them and agent token lookup, delegation walks, the hourly rate limit read and the pending approval list will scan whole tables.
On MySQL, Prisma maps
String to VARCHAR(191), so no prefix length is needed. If you manage the database with raw SQL instead, use the statements in Bring your own Drizzle.
Migration from Drizzle
If you started with the built-in Drizzle backend and want to switch to Prisma:- Keep the same table names, all theAuth tables use the
theauth_prefix and the same column names in both Drizzle and Prisma. - Run
npx prisma db pullagainst your existing database to generate a Prisma schema from the Drizzle-created tables, or copy the reference schema. - Replace calls to the Drizzle
dbdirectly withcreatePrismaAdapter(prisma). - Set
database.skipMigrations: trueincreateTheAuth(...)if the core theAuth instance is still used for other features (agents, MCP, etc.), so Drizzle does not conflict with Prisma.
Reference schema
The full reference schema is innode_modules/@glinr/theauth-prisma/src/schema.prisma. It includes 39 theAuth models with column mappings, indexes, and default values.
Every model name follows TheAuthPascalCase and maps to a theauth_snake_case table, keeping your Prisma namespace clean and your SQL tables clearly scoped.
Related
Database setup
Core database configuration and provider options.
Configuration
Full createTheAuth() options including database connection setup.
Test utilities
Test auth-dependent code with in-memory mock factories.
Migrate from better-auth
Migration guide for moving from better-auth.