Database
The package needs PostgreSQL 13 or newer. It has no ORM and no driver of its own. It uses yours.
| Driver | Config |
|---|---|
| Bun (built in) | db: process.env.DATABASE_URL or db: bunSql(Bun.sql) |
| node-postgres | db: pg(pool) |
| postgres.js | db: postgresJs(sql) |
| Drizzle | db: pg(drizzle.$client) or postgresJs(drizzle.$client) |
| Prisma | Use the URL on Bun, or a pg pool with the same URL |
Any other driver works through the Db interface:
interface Db {
query<T>(sql: string, params?: unknown[]): Promise<T[]>; // $1, $2, … placeholders
transaction<T>(fn: (tx: Db) => Promise<T>): Promise<T>;
}Tables
All tables are in the auth schema (change it with schema):
| Table | Contents |
|---|---|
users |
id (uuid), email, email_verified_at, name, image, password_hash |
accounts |
Google/GitHub accounts linked to users |
sessions |
SHA-256 of the token, user, method, active workspace, IP, user agent, expiry |
email_tokens |
Hashes of verification, reset and e-mail change links |
challenges |
Two-factor sign-in steps |
rate_limits |
Counters, keyed by a hash |
two_factor, recovery_codes |
Encrypted TOTP secrets, hashed recovery codes |
workspaces, members, invites |
Workspaces module |
api_tokens |
Hashes of API tokens |
Point your tables at auth.users(id) and auth.workspaces(id) with on delete cascade.
Migrations
With migrate: "auto" (the default), the package applies its migrations on first use. A Postgres advisory lock makes this safe when several app instances start at once.
With migrate: "manual", run them in your deploy step:
bunx kaarel-auth migrate # loads src/auth.ts
bunx kaarel-auth migrate server/auth.tsor from code: await auth.migrate().
The package never changes your own tables, and migrations only add to the auth schema.