Skip to content

sharvari247/user_management

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

User Management Backend

This project is a User Management and Role-Based Access Control (RBAC) backend system used to manage users, authentication, and secure access within an application. It includes features like user login, protected routes, role assignment, and user management. The project is designed with a scalable and modular structure for real-world applications. Future improvements include permissions, audit logs, notifications, and advanced security features.

Tech Stack

  1. TypeScript
  2. Node.js
  3. Express.js
  4. PostgreSQL
  5. pg (Raw PostgreSQL Driver)
  6. JWT Authentication
  7. bcrypt
  8. Zod Validation
  9. Winston + Morgan Logging

Features

Authentication

  • User Registration
  • User Login
  • JWT Token Generation
  • Password Hashing using bcrypt
  • Protected Routes using JWT Middleware

User Management

Create User Get Logged-in User Get All Users Get User By ID Update User Soft Delete User

Role Management

Create Roles Assign Roles to Users Fetch User Roles RBAC Foundation

Validation & Middleware

Zod Request Validation Error Handling Middleware Request Logging Request ID Tracking Centralized Response Helper

Project Setup

Clone the repository

git clone <your-repository-url>
cd user_management

Install Dependencies

Backend

cd backend
pnpm install

PostgreSQL Database Setup

Install PostgreSQL

Download and install PostgreSQL from: https://www.postgresql.org/download/?utm_source=chatgpt.com

During installation: Remember your PostgreSQL password

Keep the default port as 5432

Create Database

Open PostgreSQL Shell (psql) or pgAdmin and run:

CREATE DATABASE user_management;

Configure Environment Variables

Create a .env file inside the backend folder:

PORT=5000
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=your_password
DB_NAME=user_management

Run Database Migrations

cd backend
pnpm run migration:run

Start the Project

Start Backend Server

cd backend
pnpm run dev

Frontend Setup

Prerequisites

  • Node js(v18 or Higher)
  • pnpm
  • Backend server running locally

Installation

Navigate to the frontend directory:

cd frontend

Install dependencies

pnpm install

Start the development server:

pnpm run dev

The application will be available at:

http://localhost:5173

Application Routes

Route Description
/ Welcome page
/users Displays user data from backend API

Authentication

Protected endpoints require a valid JWT token.

For development and testing, store the token in browser local storage:

localStorage.setItem(
  "token",
  "YOUR_JWT_TOKEN"
);
Verify stored token:
localStorage.getItem("token");

The frontend automatically includes the token in API requests when fetching protected resources.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors