This is a Node.js Express application that provides user authentication and authorization using JSON Web Tokens (JWT). It includes features such as user registration, login, profile management, and admin-level user management. This project serves as a robust foundation and starting point for building secure authentication and authorization mechanisms into your applications. It offers a well-structured and extensible API for implementing JSON Web Token (JWT) based authentication, allowing you to quickly integrate user registration, login, profile management, and admin-level user management functionalities into your projects.
- Clone the repository:
git clone https://github.com/your-repo/jwt-auth-express.git - Install dependencies:
yarn install - Create a
.envfile and add the following environment variables:MONGO_URI: MongoDB connection URIJWT_SECRET: Secret key for JWT signing
- Start the server:
yarn start - The server will be running at
http://localhost:5000
POST /api/users/register: Register a new userPOST /api/users/login: Log in an existing userGET /api/users/profile: Get the current user's profile (requires authentication)PUT /api/users/profile: Update the current user's profile (requires authentication)
PUT /api/users/:id: Update a user's information (requires admin role)DELETE /api/users/:id: Delete a user (requires admin role)
- Node.js
- Express
- MongoDB (with Mongoose)
- JSON Web Tokens (JWT)
- bcryptjs (for password hashing)
Contributions are welcome! Please follow the standard GitHub workflow for contributing to this project.
This project is licensed under the MIT License.