https://github.com/sapta-dev27/authentication_authorization_system_backend
Authentication and Authorization Project : User can register , login , change UserName and Email and access role based authetication ( admins and users).
https://github.com/sapta-dev27/authentication_authorization_system_backend
backend-api bycrypt express jsonwebtoken jwt-token mongodb nodejs postman role-based-access-control
Last synced: 3 months ago
JSON representation
Authentication and Authorization Project : User can register , login , change UserName and Email and access role based authetication ( admins and users).
- Host: GitHub
- URL: https://github.com/sapta-dev27/authentication_authorization_system_backend
- Owner: Sapta-Dev27
- Created: 2025-06-27T12:34:52.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-06-28T16:34:18.000Z (3 months ago)
- Last Synced: 2025-06-28T21:34:08.881Z (3 months ago)
- Topics: backend-api, bycrypt, express, jsonwebtoken, jwt-token, mongodb, nodejs, postman, role-based-access-control
- Language: JavaScript
- Homepage: https://excalidraw.com/#room=9a6ee8557c66cf297008,tnkk4ROdZvFF_TIM1V_ezQ
- Size: 76.2 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Authentication System
# Role Based Access Control
# Database Schema
# πAuthentication and Authorization Backend
A clean, modular authentication system built with **Node.js**, **Express**, and **MongoDB**, supporting secure user registration, login, and protected routes using **JWT** and **bcrypt**. This project demonstrates best practices in backend architecture, request validation, and role-based access control.
---
## π Features
- β Secure **Signup** & **Login**
- β Password hashing with **bcrypt**
- β **JWT-based** authentication
- β **Get Current User** (`/auth/me`) endpoint
- β Middleware for protected routes
- β Centralized error handling
- β Input validation (middleware schema or manual checks)
- β Optional **role-based** access (admin/subadmin)---
## π§° Tech Stack
| Tech | Description |
|--------------|----------------------------------------|
| **Node.js** | JavaScript runtime |
| **Express.js**| Web framework |
| **MongoDB** | NoSQL database |
| **Mongoose** | ODM for MongoDB |
| **JWT** | JSON Web Token for auth |
| **bcryptjs** | Secure password hashing |---
## π Project Structure
```
root
βββ π controllers # Business logic (login, register,chnageUserName , changeUserEmail etc.)
βββ π database # MongoDB connection
βββ π middlewares # Auth & role middlewares
βββ π models # Mongoose schemas/models
βββ π routes # API route definitions
βββ π server.js # App entry point
βββ π .env # Environment variables
```---
## π API Endpoints
### 1. π Register User
**Request Body:**
```"username" : "Saptarshi2003",
"useremail" : "saptarshi2003@gmail.com",
"userpassword" : "12345",
"userrole" : "subadmin"```
## 2. π Login User
**Request Body:**```
"useremail" : "saptarshi2003@gmail.com",
"userpassword" : "12345"
```
# 3. Clone the repo
**Git Clone**
```
https://github.com/Sapta-Dev27/Authentication_Authorization_System_Backend.git
```# 5. Install dependencies
```
npm install
```# 6. Setup your .env
```
MONGO_URL=MONGO_URL
PORT=8001
JWT_SECRET_KEY=saptadev27
JWT_EXPIRE_TIME=1d
```# 7. Run the server
```
npm start
```## π License
[MIT](https://choosealicense.com/licenses/mit/)
---