An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Authentication System
![WhatsApp Image 2025-06-27 at 23 22 48_e37aa675](https://github.com/user-attachments/assets/8ab18c3c-463c-4bd0-8428-b29149d26d1c)

# Role Based Access Control
![WhatsApp Image 2025-06-28 at 00 41 53_eec27301](https://github.com/user-attachments/assets/7b52ad9c-7a86-4cee-affd-330e1b672e97)

# Database Schema
![image](https://github.com/user-attachments/assets/c62ab55b-7d29-4023-b8da-11454adecad8)

# πŸ”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/)

---