Auth Domain (PostgreSQL)
This page documents the authentication schemas for projects using PostgreSQL with Drizzle ORM.
Installation Guide
To add these schemas to your project, run:
npx servercn-cli add schema authDuring installation, select PostgreSQL (Drizzle) when prompted for the database.
This will install all authentication-related schemas into the src/drizzle/schemas folder.
Database Schema Design
To see the complete database design, including the User schema from the Auth Domain, please click here visualization.
If you install schema one by one (such as auth/user and auth/session), the relationships between them won’t be automatic—you’ll need to implement them manually.
1. User Schema
The User Schema is the core component for storing user identity, credentials, and profile information.
File Path: src/drizzle/schemas/user.schema.ts
Installation:
npx servercn-cli add schema auth/user2. OTP Schema
The OTP Schema handles one-time passwords for email verification, password resets, and 2FA.
File Path: src/drizzle/schemas/otp.schema.ts
Installation:
npx servercn-cli add schema auth/otp3. Session Schema
The Session Schema manages stateful user sessions, tracking devices and IPs.
File Path: src/drizzle/schemas/session.schema.ts
Installation:
npx servercn-cli add schema auth/session4. Refresh Token Schema
The Refresh Token Schema manages long-lived tokens for JWT renewal flows.
File Path: src/drizzle/schemas/refresh-token.schema.ts
Installation:
npx servercn-cli add schema auth/refresh-token5. Export all schemas
All database schemas must be re-exported from a single entry point. This allows Drizzle to load every table definition from one file during migration generation.
File Path: src/drizzle/index.ts
This file acts as the schema registry for Drizzle.
6. drizzle.config.ts
Create a drizzle.config.ts file at the project root.
This file defines how Drizzle connects to the database and where it should read schemas and write migrations.
File Path: drizzle.config.ts
Notes:
schemamust point to the file that exports all schemas.env.DATABASE_URLshould be validated via Env Configuration before use.strict: truehelps catch schema issues early during migration generation.
If you install schema one by one (such as auth/user and auth/session), the relationships between them won’t be automatic—you’ll need to implement them manually.