Skip to content

aaradhayasingh811/auth-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Auth Service - 3D Architectural Design Platform

The Auth Service is a Node.js microservice responsible for user authentication and authorization in the 3D Architectural Design Platform. It provides secure user registration, login, JWT-based authentication, password reset via OTP, Google OAuth, and user profile management. This service is designed to be used as part of a microservices architecture and can be deployed independently.


πŸ“¦ Folder Structure

auth-service/
β”œβ”€β”€ config/           # Database and environment configuration
β”‚   └── index.js
β”œβ”€β”€ controllers/      # Business logic for authentication
β”‚   └── auth.controller.js
β”œβ”€β”€ middlewares/      # Express middlewares (e.g., authentication)
β”œβ”€β”€ models/           # Mongoose schemas
β”‚   └── user.model.js
β”œβ”€β”€ routes/           # Express route definitions
β”‚   └── auth.routes.js
β”œβ”€β”€ services/         # (Optional) Service layer for business logic
β”œβ”€β”€ utils/            # Utility functions (email, token, verification)
β”‚   β”œβ”€β”€ email.js
β”‚   β”œβ”€β”€ token.js
β”‚   └── verification.js
β”œβ”€β”€ validations/      # (Optional) Request validation logic
β”œβ”€β”€ .env              # Environment variables
β”œβ”€β”€ Dockerfile        # Docker configuration
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ package.json
β”œβ”€β”€ Readme.md
└── src/
    └── app.js        # Main Express app entry point

πŸš€ Features

  • User Registration & Login (with username/email)
  • JWT-based Authentication (access tokens via cookies)
  • Google OAuth2 Login
  • Password Reset via OTP (email-based)
  • Profile Management (get, update, delete)
  • Email Verification (token-based, optional)
  • Secure Middleware Protection
  • Docker & Docker Compose Support
  • Environment-based Configuration

🧠 Tech Stack

  • Node.js with Express
  • MongoDB with Mongoose
  • JWT for Authentication
  • bcrypt for Password Hashing
  • dotenv, cors, cookie-parser

βš™οΈ Environment Variables

Create a .env file in the project root with the following variables:

PORT=4000
MONGODB_URI=mongodb://localhost:27017/auth_service
JWT_SECRET=your_jwt_secret
GOOGLE_CLIENT_ID=your_google_client_id
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your_email@example.com
SMTP_PASS=your_email_password
FRONTEND_URL=http://localhost:5173

πŸ§ͺ API Endpoints

All endpoints are prefixed with /api/v1.

Method Endpoint Description Auth Required
POST /register Register new user ❌
POST /login Login user ❌
POST /logout Logout user βœ…
POST /auth/google Google OAuth login ❌
POST /send-otp Send OTP for password reset ❌
POST /verify-otp Verify OTP for password reset ❌
POST /reset-password Reset password using OTP ❌
GET /profile Get user profile βœ…
PUT /profile Update user profile βœ…
DELETE /profile Delete user profile βœ…

Note: Some endpoints like email verification may be implemented in utils/verification.js.


πŸ› οΈ Usage

1. Clone and Install

git clone https://github.com/yourusername/auth-service.git
cd auth-service
npm install

2. Configure Environment

Copy .env.example to .env and fill in your values.

3. Run Locally

npm start

The service will run on http://localhost:4000 by default.

4. Docker Usage

Build and Run with Docker Compose

docker-compose up --build

This will start both the auth service and a MongoDB instance.

Stop Containers

docker-compose down

πŸ“ Example Requests

Register

POST /api/v1/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "username": "johnny",
  "password": "yourpassword"
}

Login

POST /api/v1/login
Content-Type: application/json

{
  "emailOrUsername": "john@example.com",
  "password": "yourpassword"
}

Send OTP

POST /api/v1/send-otp
Content-Type: application/json

{
  "email": "john@example.com"
}

Reset Password

POST /api/v1/reset-password
Content-Type: application/json

{
  "email": "john@example.com",
  "otp": "123456",
  "password": "newpassword"
}

πŸ”’ Security Notes

  • Passwords are hashed using bcrypt before storage.
  • JWT tokens are signed with a secret and sent as HTTP-only cookies.
  • OTPs for password reset are time-limited and stored securely.
  • CORS is configured to allow requests from the frontend URL.
  • Sensitive configuration is managed via environment variables.

🧩 Extending the Service

  • Add more social login providers (Facebook, GitHub, etc.)
  • Implement rate limiting for brute-force protection.
  • Add email verification flow (see utils/verification.js).
  • Integrate with a user management dashboard.

πŸ§‘β€πŸ’» Contributing

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a pull request

πŸ“„ License

This project is licensed under the ISC License.


πŸ“¬ Contact

For questions, contact your-email@example.com.


πŸ“š Related Files


Happy Coding!

About

πŸ” Auth Microservice – ArchitechX The Auth microservice handles secure authentication and authorization using JWT in ArchitechX. It supports user sign-up, login, and role-based access, ensuring only verified users can access protected services. This service forms the security backbone of the platform.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors