A secure REST API demonstrating user authentication and authorization using Node.js, Express, MongoDB, JWT, and bcrypt.
This project showcases modern backend authentication practices including password hashing, JSON Web Tokens, middleware-based route protection, and RESTful API development.
- User Registration
- User Login
- Password Hashing (bcrypt)
- JWT Authentication
- Protected Routes
- MongoDB Integration
- Express Middleware
- Environment Variable Support
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT
- bcrypt
- dotenv
cohort-2-auth_last/
│
├── controllers/
├── middleware/
├── models/
├── routes/
├── server.js
├── package.json
└── README.md
Clone the repository
git clone https://github.com/RhemaGreat/cohort-2-auth_last.gitInstall dependencies
npm installCreate a .env file
PORT=5000
MONGODB_URI=your_database_connection
ACCESS_TOKEN_SECRET=your_access_secret
REFRESH_TOKEN_SECRET=your_refresh_secretStart the server
npm startor
npm run dev| Method | Endpoint | Description |
|---|---|---|
| POST | /register | Register a new user |
| POST | /login | Authenticate a user |
| POST | /logout | Logout a user |
| GET | /profile | Protected user profile |
After successful login, include your access token:
Authorization: Bearer YOUR_ACCESS_TOKEN
- Password hashing using bcrypt
- JWT Authentication
- Protected routes
- Environment variables
- Middleware-based authorization
This project demonstrates:
- REST API Development
- Authentication
- Authorization
- JWT
- Password Security
- Express Middleware
- MongoDB Integration
- Backend Architecture
- Email Verification
- Password Reset
- Role-Based Access Control (RBAC)
- Rate Limiting
- Refresh Token Rotation
- Swagger Documentation
- Unit Testing
- Docker Support
- GitHub Actions
- Two-Factor Authentication (2FA)
Pull requests are welcome.
- API Documentation
- Unit Tests
- Docker
- CI/CD
- RBAC
- Refresh Token Rotation
- Password Reset
- Email Verification
Rhema Great
GitHub: https://github.com/RhemaGreat
Licensed under the MIT License.