Microservice responsible for user registration, authentication, JWT management, and session control.
- User Registration: Password hashing (bcrypt) and delegation to User Service.
- Login: Credential verification and token issuance.
- Token Management: JWT access tokens and hashed opaque refresh tokens.
- Security: Token rotation, database-level expiry (TTL), and service-to-service internal secrets.
- Events: Publishing lifecycle events to RabbitMQ.
- Node.js & TypeScript
- Express.js
- MongoDB (Mongoose)
- RabbitMQ (amqplib)
- JWT (jsonwebtoken)
- Zod (validation)
- Swagger (documentation)
- Jest (testing)
Copy .env.example to .env and fill in the values:
| Variable | Description | Default |
|---|---|---|
| PORT | Service port | 3001 |
| MONGODB_URI | MongoDB connection string | mongodb://localhost:27017/auth-service |
| JWT_ACCESS_SECRET | Secret for access tokens | (Required) |
| JWT_REFRESH_SECRET | Secret for refresh tokens | (Required) |
| ACCESS_TOKEN_EXPIRY | Access token duration | 15m |
| REFRESH_TOKEN_EXPIRY | Refresh token duration | 7d |
| USER_SERVICE_URL | URL of the User Service | http://localhost:3002 |
| RABBITMQ_URL | RabbitMQ connection string | amqp://localhost:5672 |
| INTERNAL_SECRET | Shared secret for S2S auth | (Required) |
- Install dependencies:
npm install
- Start in dev mode:
npm run dev
docker build -t auth-service .
docker run -p 3001:3001 auth-serviceOnce the service is running, visit:
http://localhost:3001/api/auth/docs
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage