Skip to content

Y4-CTSE-Assignment-Group-83/User_Auth_Service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

94 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Salon Booking System – User Authentication Service

This repository contains the User Authentication and Role Management Microservice for the Salon Booking System. It is responsible for handling authentication, authorization, user profile management, and password reset functionality for different system roles.

The service is built using Node.js, Express.js, MongoDB, and JWT authentication, following microservice architecture principles.


πŸš€ Features

Authentication

  • Customer registration
  • Login for all roles (Admin, Staff, Customer)
  • Secure JWT authentication
  • HTTP-only cookie based session handling

Authorization

  • Role-based access control
  • Admin
  • Staff
  • Customer

User Management

Admin can manage:

  • Staff accounts
  • Customer accounts

Operations include:

  • Create users
  • View users
  • Update users
  • Delete users

Profile Management

Each user can manage their own profile:

Staff:

  • View profile
  • Update profile

Customer:

  • View profile
  • Update profile

Password Reset System

Secure password recovery mechanism:

  1. Forgot password request
  2. Reset token generated
  3. Email sent using Nodemailer
  4. Password reset using token
  5. All previous sessions invalidated after password reset

Security Features

  • Password hashing using bcrypt
  • JWT authentication
  • Token expiration
  • Session invalidation after password reset
  • Input validation using express-validator
  • Protected routes with middleware
  • HTTP-only cookies
  • Role based route protection

API Documentation

The API documentation is provided using Swagger UI.

Swagger provides:

  • Interactive API testing
  • Request body schemas
  • Authentication support
  • Endpoint descriptions

Swagger URL:

http://localhost:5000/api-docs

πŸ— Tech Stack

Backend Framework

  • Node.js
  • Express.js

Database

  • MongoDB
  • Mongoose

Authentication

  • JWT (JSON Web Tokens)
  • bcrypt password hashing

Email Service

  • Nodemailer
  • Gmail SMTP

API Documentation

  • Swagger
  • swagger-jsdoc
  • swagger-ui-express

Validation

  • express-validator

πŸ“‚ Project Structure

backend
β”‚
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ config
β”‚   β”‚   └── db.js
β”‚
β”‚   β”œβ”€β”€ controllers
β”‚   β”‚   β”œβ”€β”€ auth.controller.js
β”‚   β”‚   β”œβ”€β”€ staff.controller.js
β”‚   β”‚   β”œβ”€β”€ staff_management.controller.js
β”‚   β”‚   β”œβ”€β”€ customer.controller.js
β”‚   β”‚   └── customer_management.controller.js
β”‚
β”‚   β”œβ”€β”€ middleware
β”‚   β”‚   β”œβ”€β”€ auth.middleware.js
β”‚   β”‚   └── validate.middleware.js
β”‚
β”‚   β”œβ”€β”€ models
β”‚   β”‚   └── user.model.js
β”‚
β”‚   β”œβ”€β”€ routes
β”‚   β”‚   β”œβ”€β”€ auth.routes.js
β”‚   β”‚   β”œβ”€β”€ staff.routes.js
β”‚   β”‚   β”œβ”€β”€ staff_management.routes.js
β”‚   β”‚   β”œβ”€β”€ customer.routes.js
β”‚   β”‚   └── customer_management.routes.js
β”‚
β”‚   β”œβ”€β”€ validators
β”‚   β”‚   β”œβ”€β”€ auth.validators.js
β”‚   β”‚   β”œβ”€β”€ staff.validators.js
β”‚   β”‚   β”œβ”€β”€ staff_management.validators.js
β”‚   β”‚   β”œβ”€β”€ customer.validators.js
β”‚   β”‚   └── customer_management.validators.js
β”‚
β”‚   β”œβ”€β”€ utils
β”‚   β”‚   β”œβ”€β”€ generateToken.js
β”‚   β”‚   └── emailService.js
β”‚
β”‚   └── swagger
β”‚       └── swagger.js
β”‚
β”œβ”€β”€ index.js
β”œβ”€β”€ .env
└── package.json

βš™οΈ Installation Guide

2️⃣ Install Dependencies

pnpm install

3️⃣ Setup Environment Variables

Create a .env file.

PORT=5000

MONGO_URI=your_mongodb_connection_string

JWT_SECRET=your_secret_key

EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_gmail_app_password

FRONTEND_URL=http://localhost:3000

4️⃣ Start Server

pnpm run dev

Server runs on:

http://localhost:5000

πŸ“– API Endpoints Overview

Authentication

POST /api/auth/register
POST /api/auth/login
POST /api/auth/logout
GET  /api/auth/me

Password Management

POST /api/auth/forgot-password
POST /api/auth/reset-password/:token

Staff Profile

GET  /api/staff/profile
PUT  /api/staff/profile

Customer Profile

GET  /api/customer/profile
PUT  /api/customer/profile

Admin – Staff Management

POST   /api/staff-management/create
GET    /api/staff-management/getall
GET    /api/staff-management/get/:id
PUT    /api/staff-management/update/:id
DELETE /api/staff-management/delete/:id

Admin – Customer Management

GET    /api/customer-management/getall
GET    /api/customer-management/get/:id
PUT    /api/customer-management/update/:id
DELETE /api/customer-management/delete/:id

πŸ” Role Based Access

Role Permissions
Admin Manage staff and customers
Staff Manage own profile
Customer Manage own profile

πŸ“§ Password Reset Flow

  1. User requests password reset
POST /api/auth/forgot-password
  1. Reset email is sent

  2. User clicks reset link

POST /api/auth/reset-password/:token
  1. Password updated and sessions invalidated

πŸ§ͺ API Testing

API can be tested using:

  • Swagger UI
  • Postman
  • Thunder Client
  • cURL

Swagger URL:

http://localhost:5000/api-docs

πŸ›‘ Security Practices Implemented

  • JWT authentication
  • Secure password hashing
  • Input validation
  • Role-based access control
  • Session invalidation
  • Secure cookies
  • Password reset token expiration

πŸ‘¨β€πŸ’» Author

Nagahawaththa J.C.D - IT22573896

Developed as part of the SE4010 – Current Trends in Software Engineering module assignment.

Sri Lanka Institute of Information Technology (SLIIT)


About

User Authentication & Role Management Microservice for a Salon Booking System built with Node.js, Express, MongoDB, JWT authentication, Swagger API documentation, and secure password reset functionality.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors