Skip to content

YNS-JNS/AuthFlow-Mern-RBAC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


User Authentication & Authorization with JWT and RBAC

This project implements a user authentication and authorization system using Node.js, Express.js, MongoDB, React.js, and Redux Toolkit. It also includes CRUD API endpoints for user management and implements dynamic Role-based Access Control (RBAC) in the REST API.

Features

  • User signup (registration)
  • User login (authentication)
  • User logout
  • CRUD API endpoints for user management
  • Dynamic Role-based Access Control (RBAC) in REST API
  • Secure JWT-based authentication
  • Password hashing for user security

Project Structure

AuthFlow-Mern-RBAC/
│
├── server/        # Backend Node.js and Express.js application
│   ├── config/    # Configuration files (e.g., database, JWT secret)
│   ├── controllers/   # Route controllers
│   ├── middleware/    # Custom middleware (e.g., authentication, authorization)
│   ├── models/        # MongoDB models (e.g., User)
│   ├── routes/        # Route definitions
│   └── app.js         # Express application setup
│
└── client/       # Frontend React.js application
    ├── public/     # Static files (HTML, assets)
    ├── src/        # React source code
    │   ├── components/  # Reusable UI components
    │   ├── features/    # Redux Toolkit slices for managing user state
    │   ├── pages/       # React components for different pages (e.g., login, signup)
    │   ├── App.js       # Main React application component
    │   ├── index.js     # Entry point for React application
    │   └── ...
    │
    ├── package.json    # Frontend dependencies and scripts
    └── ...

Setup Instructions

Clone the repository

git clone https://github.com/YNS-JNS/AuthFlow-Mern-RBAC.git

Backend Setup

  1. Install dependencies:

    cd server
    npm install
  2. Configure environment variables:

    • Create a .env file in the backend directory.
    • Define the following variables:
      PORT=3000
      MONGODB_URI=mongodb://localhost:27017/your_database_name
      JWT_SECRET=your_jwt_secret_key
      
  3. Start the backend server:

    npm start

Frontend Setup

  1. Install dependencies:

    cd client
    npm install
  2. Start the frontend development server:

    npm start
  3. Access the application in your browser at http://localhost:3000.

API Endpoints

The backend exposes the following API endpoints:

  • POST /api/auth/signup: User signup (registration)
  • POST /api/auth/signin: User login (authentication)
  • POST /api/auth/logout: User logout
  • GET /api/users: Get all users (requires admin role)
  • GET /api/users/:id: Get user by ID (requires admin role)
  • PUT /api/users/:id: Update user by ID (requires admin role)
  • DELETE /api/users/:id: Delete user by ID (requires admin role)

Authentication & Authorization

  • User authentication is based on JWT (JSON Web Tokens).
  • User roles (e.g., admin, user) are used for RBAC (Role-based Access Control) in API endpoints.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Feel free to customize the README.md file according to your project's specific requirements and add more detailed instructions or information as needed.

About

Authentication using MERN Stack

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages