A production-ready authentication system built with Node.js, Express, MongoDB, and JWT. This project demonstrates industry-level authentication architecture including Access Tokens, Refresh Tokens, Token Rotation, Session Management, OTP verification, and secure multi-device logout.
This system simulates how modern applications handle authentication securely and efficiently.
- Access Token (short-lived)
- Refresh Token (long-lived)
- Secure token verification middleware
- Refresh token changes on every request
- Prevents token reuse attacks
- Enhances overall security
-
Each login creates a session
-
Tracks:
- IP Address
- Device (User-Agent)
-
Supports multi-device login
- Logout from a single device
- Logout from all devices
- Session revocation support
- Email-based OTP verification
- Secure OTP generation & validation
- Expiry-based OTP system
- Hashed refresh tokens
- Optional token blacklist
- Input validation
- Protected routes middleware
Client → API (Express)
↓
Controllers
↓
Services
↓
Models (Mongoose)
↓
MongoDB
- User sends login request
- Access Token and Refresh Token are generated
- Refresh token is hashed and stored in the database
- A session is created with device and IP information
- Client sends refresh token
- Server verifies session and token
- New access token is generated
- New refresh token is issued (rotation)
- Single device logout → specific session revoked
- Logout from all devices → all sessions revoked
- User requests OTP
- Server generates OTP
- OTP is sent via email
- User verifies OTP to complete authentication
- JWT verification
- Refresh token hashing
- Session-based authentication
- Token rotation
- OTP verification
- Logout from all devices
project-root/
│
├── controllers/
├── models/
├── routes/
├── middlewares/
├── services/
├── utils/
├── config/
└── server.js
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT
# Clone the repository
git clone https://github.com/yeasin-riyad/Advance-Authentication-System.git
# Install dependencies
npm install
# Run server
npm run devCreate a .env file:
PORT=5000
MONGO_URI=your_mongodb_uri
JWT_ACCESS_SECRET=your_access_secret
JWT_REFRESH_SECRET=your_refresh_secret
OTP_SECRET=your_otp_secret
POST /api/auth/login{
"email": "user@example.com",
"password": "123456"
}🚀 Base URL:
https://advance-backend-ledger.onrender.com
POST https://advance-backend-ledger.onrender.com/api/auth/login- Access & Refresh Token Strategy
- Token Rotation
- Session-Based Authentication
- OTP Verification System
- Secure Logout (Single + All Devices)
- Redis for session storage
- Rate limiting & brute-force protection
- Social login (Google, Facebook)
- Multi-factor authentication (MFA)
Yeasin Mazumder
⭐ If you like this project, give it a star!