Skip to main content
theAuth ships a Drizzle-based database layer by default. If your project already uses Prisma, the @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.
The adapter has methods for users, agents, permissions, delegation chains, audit logs, sessions, rate limits, OAuth clients, tokens and authorization codes, MCP servers, API keys, organizations, members and invitations, JWT refresh tokens, trust scores, and approval requests. The reference Prisma schema defines more models than the adapter has methods for (for example magic links, passkeys, and SSO connections), so for those tables use Prisma models directly.

Installation

The package declares @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 from node_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.
2

Run migrations

Or push to an existing database without a migration file:
3

Create the adapter

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

A request can need several distinct approvers. Create it with 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:
The composite primary key on 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 reference schema.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:
  1. Keep the same table names, all theAuth tables use the theauth_ prefix and the same column names in both Drizzle and Prisma.
  2. Run npx prisma db pull against your existing database to generate a Prisma schema from the Drizzle-created tables, or copy the reference schema.
  3. Replace calls to the Drizzle db directly with createPrismaAdapter(prisma).
  4. Set database.skipMigrations: true in createTheAuth(...) if the core theAuth instance is still used for other features (agents, MCP, etc.), so Drizzle does not conflict with Prisma.
The core theAuth instance (createTheAuth) still uses Drizzle internally for agent creation, authorization, MCP flows, and other built-in features. @glinr/theauth-prisma gives you a Prisma-native way to read and write the same tables, it does not replace createTheAuth.

Reference schema

The full reference schema is in node_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.

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.
Last modified on October 19, 2026