Skip to content

Kareems3eed/Auth-Service

Repository files navigation

Auth Service

Microservice responsible for user registration, authentication, JWT management, and session control.

🚀 Features

  • 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.

🛠️ Tech Stack

  • Node.js & TypeScript
  • Express.js
  • MongoDB (Mongoose)
  • RabbitMQ (amqplib)
  • JWT (jsonwebtoken)
  • Zod (validation)
  • Swagger (documentation)
  • Jest (testing)

⚙️ Environment Variables

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)

📦 Getting Started

Local Development

  1. Install dependencies:
    npm install
  2. Start in dev mode:
    npm run dev

Using Docker

docker build -t auth-service .
docker run -p 3001:3001 auth-service

📚 API Documentation

Once the service is running, visit: http://localhost:3001/api/auth/docs

🧪 Testing

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

About

Auth Service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors