- Overview
- Environmental Variables
- Routes
- Authentication and Authorization
- JWT Token Expiry
- Docker-Compose and MongoDB Setup
- Getting Started
- License
- Contributors
- Contact me
This Node Authorization API allows users to perform authentication and authorization actions through a set of RESTful routes. The key technologies used in this project include:
- bcrypt: Used for hashing passwords securely.
- cookie-parser: Parses cookies attached to the client's request.
- cors: Enables Cross-Origin Resource Sharing.
- dotenv: Loads environment variables from a .env file.
- express: A fast, unopinionated, minimalist web framework for Node.js.
- joi: A schema description language and data validator.
- jsonwebtoken: Generates and verifies JSON Web Tokens (JWT).
- mongoose: An ODM library for MongoDB and Node.js.
Ensure the following environmental variables are set:
PORT: Port number for the server.
MONGODB_URL: URL for the MongoDB database.
JWT_SECRET: Secret key for JWT token generation and verification.
- POST /signup: Create a new user.
- POST /login: Log in with existing credentials.
- GET /: Retrieve all users (requires authentication).
- GET /:email: Retrieve a specific user by email (requires authentication).
- POST /:email: Update a user by email (requires authentication).
- DELETE /:email: Delete a user by email (requires authentication).
- Users can only access the login and signup routes publicly.
- Other routes are private and require authentication, implemented through middleware and a validation function.
- JWT tokens have a 3-day expiration, requiring users to log in again after that time.
- The project includes a docker-compose file for creating a MongoDB database.
- MongoDB is accessible via the Mongo Express service for database management.
- The admin passphrase in the docker-compose file is for development only and should be a stronger password in production.
- Clone the repository.
- Set up the environmental variables in a .env file.
- Run docker-compose up -d to start the MongoDB and Mongo Express services.
- Install dependencies with npm install.
- Start the server with npm start.
- Explore the API using the provided routes.
This is an open-source library and is available under the MIT License. You are free to use, modify, and distribute the code in accordance with the terms of the license.
Linkedin: feliperdamaceno