A robust and secure REST API for user authentication and authorization built with Node.js, Express, and MongoDB. This project provides a solid foundation for managing secure access using JSON Web Tokens (JWT).
- ๐ JWT Authentication: Secure token generation and verification.
- ๐ก๏ธ Enhanced Security: Integrated with
helmetfor HTTP headers andcorsfor cross-origin resource sharing. - ๐งช Data Validation: Strict input validation using
Joito ensure data integrity. - ๐ Password Hashing: User passwords are safely hashed using
bcrypt. - โ๏ธ Global Error Handling: Centralized middleware for catching errors and handling 404 routes.
- ๐ Environment Configuration: Secure management of sensitive data via
.env.
-
Clone the repository:
git clone https://github.com/sebastianvasquezechavarria1234/auth-shield-api.git
-
Install dependencies:
npm install
-
Configure environment variables:
- Create a
.envfile in the root directory based on.env.example. - Add your MongoDB URI and a secure TOKEN_SECRET.
- Create a
-
Start the server:
npm run dev
POST /api/user/register- Register a new user.POST /api/user/login- Login and receive an access token.
GET /api/dashboard- Sample protected route (requiresauth-tokenheader).
The application requires the following variables in your .env file:
| Variable | Description |
|---|---|
MONGODB_URI |
Your MongoDB Atlas connection string. |
TOKEN_SECRET |
A long, random string to sign your JWTs. |
PORT |
The port for the server (default: 3001). |
- Backend: Node.js, Express.js
- Database: MongoDB (Mongoose)
- Security: Jsonwebtoken, Bcrypt, Helmet, Cors
- Validation: Joi
This project is licensed under the ISC License.