Hybrid Authentication with MySQL (Drizzle)
MySQL implementation of hybrid authentication using Drizzle ORM for users and Redis for session tracking and refresh token rotation.
Installation Guide
Run the following command:
npx servercn-cli@latest add bp hybrid-authAdd the following scripts to your package.json:
Key Features
- MySQL + Drizzle ORM for type-safe database operations
- JWT access/refresh token rotation with Redis-backed sessions
- OAuth support (GitHub, Google) via Passport.js
- OTP-based email verification and password reset
- Account lockout after failed login attempts
- Soft/hard account deletion with reactivation support
- Cloudinary file upload integration for avatars
- Rate limiting and security headers
API 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 |
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: