Stateful Auth with MongoDB (Mongoose)
Session-based authentication using MongoDB and Mongoose with server-managed sessions.
You can add the stateful authentication blueprint to your project using the Servercn CLI:
npx servercn-cli@latest add blueprint stateful-auth
All endpoints are the same for both MVC and Feature architectures.
| Method | Endpoint | Description |
|---|
| POST | /verify-otp | Verify OTP for email verification |
| POST | /signup | Register new user |
| POST | /signin | Login user |
| GET | /profile | Get user profile |
| PATCH | /profile | Update profile (with avatar) |
| POST | /logout | Logout current user |
| POST | /forgot-password | Request password reset OTP |
| POST | /reset-password | Reset password with OTP |
| POST | /change-password | Change current password |
| DELETE | /delete-account | Soft delete account |
| PUT | /reactivate-account | Restore deleted account |
| Method | Endpoint | Description |
|---|
| GET | /sessions | Get all active user sessions |
| DELETE | /sessions | Revoke all sessions except current |
| DELETE | /sessions/:sessionId | Revoke specific session |
| Method | Endpoint | Description |
|---|
| GET | /github | Initiate GitHub OAuth |
| GET | /github/callback | GitHub OAuth callback |
| GET | /google | Initiate Google OAuth |
| GET | /google/callback | Google OAuth callback |
| Method | Endpoint | Description |
|---|
| GET | / | Basic health check |
| GET | /detailed | Detailed health status |
auth.controller.ts - Handles signup, signin, profile management, password operations, session management
oauth.controller.ts - GitHub & Google OAuth callback handlers
health.controller.ts - Basic and detailed health checks
auth.service.ts - Core authentication business logic
email.service.ts - Email delivery using Nodemailer
otp.service.ts - OTP generation, hashing, and verification
upload.service.ts - Cloudinary file upload integration
user.model.ts - User schema with hooks and instance methods
session.model.ts - Session tracking schema
otp.model.ts - One-time password schema
auth.routes.ts - All authentication endpoints
oauth.routes.ts - OAuth flow routes
health.routes.ts - Health check endpoints