A clean, modular authentication system built with Node.js, Express, and MongoDB, supporting secure user registration, login, and protected routes using JWT and bcrypt. This project demonstrates best practices in backend architecture, request validation, and role-based access control.
- ✅ Secure Signup & Login
- ✅ Password hashing with bcrypt
- ✅ JWT-based authentication
- ✅ Get Current User (
/auth/me
) endpoint - ✅ Middleware for protected routes
- ✅ Centralized error handling
- ✅ Input validation (middleware schema or manual checks)
- ✅ Optional role-based access (admin/subadmin)
Tech | Description |
---|---|
Node.js | JavaScript runtime |
Express.js | Web framework |
MongoDB | NoSQL database |
Mongoose | ODM for MongoDB |
JWT | JSON Web Token for auth |
bcryptjs | Secure password hashing |
root
├── 📁 controllers # Business logic (login, register,chnageUserName , changeUserEmail etc.)
├── 📁 database # MongoDB connection
├── 📁 middlewares # Auth & role middlewares
├── 📁 models # Mongoose schemas/models
├── 📁 routes # API route definitions
├── 📄 server.js # App entry point
├── 📄 .env # Environment variables
Request Body:
"username" : "Saptarshi2003",
"useremail" : "saptarshi2003@gmail.com",
"userpassword" : "12345",
"userrole" : "subadmin"
Request Body:
"useremail" : "saptarshi2003@gmail.com",
"userpassword" : "12345"
Git Clone
https://github.com/Sapta-Dev27/Authentication_Authorization_System_Backend.git
npm install
MONGO_URL=MONGO_URL
PORT=8001
JWT_SECRET_KEY=saptadev27
JWT_EXPIRE_TIME=1d
npm start