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.
- 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
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
└── ...
git clone https://github.com/YNS-JNS/AuthFlow-Mern-RBAC.git
-
Install dependencies:
cd server npm install
-
Configure environment variables:
- Create a
.env
file in thebackend
directory. - Define the following variables:
PORT=3000 MONGODB_URI=mongodb://localhost:27017/your_database_name JWT_SECRET=your_jwt_secret_key
- Create a
-
Start the backend server:
npm start
-
Install dependencies:
cd client npm install
-
Start the frontend development server:
npm start
-
Access the application in your browser at
http://localhost:3000
.
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 logoutGET /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)
- 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.
Contributions are welcome! Please fork the repository and submit a pull request.
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.