A Node.js-based authentication system with Docker containerization, featuring user registration, login, password reset, and JWT authentication with rate limiting.
- User Registration and Login
- Password Reset Functionality
- JWT Authentication
- Dockerized Environment
- Rate Limiting for API Protection
- Docker and Docker Compose installed
.
├── Dockerfile
├── docker-compose.yml
├── package.json
├── app.js
├── routes
│ ├── auth.js
└── .env
Create a .env file in the root directory with the following:
PORT=3000
JWT_SECRET=your_jwt_secret
REFRESH_SECRET=your_refresh_secret
EMAIL=your_email@gmail.com
PASS=your_email_password
- Build Docker Image:
docker-compose build- Run Docker Container:
docker-compose upThe API will be available at http://localhost:3000/auth
curl -X POST "http://localhost:3000/auth/register" \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com", "password":"yourpassword"}'curl -X POST "http://localhost:3000/auth/login" \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com", "password":"yourpassword"}'curl -X POST "http://localhost:3000/auth/refresh" \
-H "Content-Type: application/json" \
-d '{"token":"your_refresh_token"}'curl -X POST "http://localhost:3000/auth/logout" \
-H "Content-Type: application/json" \
-d '{"token":"your_refresh_token"}'curl -X POST "http://localhost:3000/auth/reset-password-request" \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com"}'curl -X POST "http://localhost:3000/auth/reset-password" \
-H "Content-Type: application/json" \
-d '{"token":"reset_token", "newPass":"newpassword"}'curl -X GET "http://localhost:3000/auth/profile" \
-H "Authorization: Bearer your_access_token"The system implements rate limiting to restrict the number of requests per user:
- Limit: 100 requests per 15 minutes.
Create a file test_rate_limit.sh with the following content:
#!/bin/bash
for i in {1..110}
do
echo "Request #$i"
curl -X GET "http://localhost:3000/auth/profile" \
-H "Authorization: Bearer your_access_token"
echo "\n"
sleep 1
doneRun the script:
bash test_rate_limit.shYou should start receiving 429 Too Many Requests after the 100th request.
docker-compose downMIT License