Auth Domain (MongoDB)
This page documents the authentication schemas for projects using MongoDB with Mongoose.
The Auth Domain provides a set of production-ready models that handle user identity, verification, and session management.
Installation Guide
To add these schemas to your project, run:
npx servercn-cli add schema authDuring initialize the servercn in your project, select MongoDB when prompted for the database.
Database Schema Design
To see the complete database design, including the User schema from the Auth Domain, please click here visualization.
1. User Schema
The User Schema is the core component for storing user identity, credentials, and profile information.
MVC Path: src/models/user.model.ts
Feature Path: src/modules/auth/user.model.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.
MVC Path: src/models/otp.model.ts
Feature Path: src/modules/auth/otp.model.ts or src/modules/otp/otp.model.ts
Installation:
npx servercn-cli add schema auth/otp3. Session Schema
The Session Schema manages stateful user sessions, tracking devices and IPs.
MVC Path: src/models/session.model.ts
Feature Path: src/modules/auth/session.model.ts
Installation:
npx servercn-cli add schema auth/session4. Refresh Token Schema
The Refresh Token Schema manages long-lived tokens for JWT renewal flows.
MVC Path: src/models/refresh-token.model.ts
Feature Path: src/modules/auth/refresh-token.model.ts
Installation:
npx servercn-cli add schema auth/refresh-token5. Auth Constants
The Auth Constants file centralizes all authentication-related configuration values, such as OTP expiry times, maximum login attempts, and token durations.
MVC Path: src/constants/auth.ts
Feature Path: src/shared/constants/auth.ts