Coder Social home page Coder Social logo

authflow-mern-rbac's Introduction


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.

authflow-mern-rbac's People

Contributors

yns-jns avatar

Stargazers

Zakaria Ghachim avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.