Hybrid Authentication with MongoDB (Mongoose)
MongoDB implementation of hybrid authentication using Mongoose for users and Redis for session tracking and refresh token rotation.
Installation Guide
Add the hybrid authentication blueprint using the Servercn CLI:
npx servercn-cli add blueprint hybrid-authAPI Endpoints
All endpoints are the same for both MVC and Feature architectures.
Authentication Routes
Base URL: http://localhost:9000/api/v1/auth
| Method | Endpoint | Description |
|---|---|---|
| POST | /signup | Register new user and send verification OTP |
| POST | /verify-user | Verify email with OTP |
| POST | /signin | Login user and set auth cookies |
| GET | /profile | Get current user profile |
| PATCH | /profile | Update profile and avatar |
| GET | /sessions | List active sessions |
| DELETE | /sessions | Revoke all sessions except current |
| DELETE | /sessions/:sessionId | Revoke a specific session |
| POST | /refresh-token | Rotate access and refresh tokens |
| POST | /logout | Logout current session |
| POST | /forgot-password | Request password reset OTP |
| POST | /verify-reset-otp | Verify password reset OTP |
| POST | /reset-password | Reset password after OTP verification |
| POST | /change-password | Change password and revoke sessions |
| POST | /account/request-delete | Request account deletion token |
| DELETE | /account/delete | Delete or deactivate account by token |
| PUT | /account/reactivate | Reactivate soft-deleted account |
OAuth Routes
Base URL: http://localhost:9000/api/auth
| Method | Endpoint | Description |
|---|---|---|
| GET | /github | Initiate GitHub OAuth |
| GET | /github/callback | GitHub OAuth callback |
| GET | Initiate Google OAuth | |
| GET | /google/callback | Google OAuth callback |
| GET | Initiate Facebook OAuth | |
| GET | /facebook/callback | Facebook OAuth callback |
Health Check
Base URL: http://localhost:9000/api/v1/health
| Method | Endpoint | Description |
|---|---|---|
| GET | / | Basic health check |
| GET | /detailed | Detailed health status |
Environment Variables
Create a .env file with the following: