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.
- Customer registration
- Login for all roles (Admin, Staff, Customer)
- Secure JWT authentication
- HTTP-only cookie based session handling
- Role-based access control
- Admin
- Staff
- Customer
Admin can manage:
- Staff accounts
- Customer accounts
Operations include:
- Create users
- View users
- Update users
- Delete users
Each user can manage their own profile:
Staff:
- View profile
- Update profile
Customer:
- View profile
- Update profile
Secure password recovery mechanism:
- Forgot password request
- Reset token generated
- Email sent using Nodemailer
- Password reset using token
- All previous sessions invalidated after password reset
- 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
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
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
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
pnpm install
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
pnpm run dev
Server runs on:
http://localhost:5000
POST /api/auth/register
POST /api/auth/login
POST /api/auth/logout
GET /api/auth/me
POST /api/auth/forgot-password
POST /api/auth/reset-password/:token
GET /api/staff/profile
PUT /api/staff/profile
GET /api/customer/profile
PUT /api/customer/profile
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
GET /api/customer-management/getall
GET /api/customer-management/get/:id
PUT /api/customer-management/update/:id
DELETE /api/customer-management/delete/:id
| Role | Permissions |
|---|---|
| Admin | Manage staff and customers |
| Staff | Manage own profile |
| Customer | Manage own profile |
- User requests password reset
POST /api/auth/forgot-password
-
Reset email is sent
-
User clicks reset link
POST /api/auth/reset-password/:token
- Password updated and sessions invalidated
API can be tested using:
- Swagger UI
- Postman
- Thunder Client
- cURL
Swagger URL:
http://localhost:5000/api-docs
- JWT authentication
- Secure password hashing
- Input validation
- Role-based access control
- Session invalidation
- Secure cookies
- Password reset token expiration
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)