Skip to content

sebastianvasquezechavarria1234/auth-shield-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ Auth Shield API

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).


๐Ÿš€ Features

  • ๐Ÿ” JWT Authentication: Secure token generation and verification.
  • ๐Ÿ›ก๏ธ Enhanced Security: Integrated with helmet for HTTP headers and cors for cross-origin resource sharing.
  • ๐Ÿงช Data Validation: Strict input validation using Joi to 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.

๐Ÿ› ๏ธ Installation

  1. Clone the repository:

    git clone https://github.com/sebastianvasquezechavarria1234/auth-shield-api.git
  2. Install dependencies:

    npm install
  3. Configure environment variables:

    • Create a .env file in the root directory based on .env.example.
    • Add your MongoDB URI and a secure TOKEN_SECRET.
  4. Start the server:

    npm run dev

๐Ÿ”Œ API Endpoints

๐Ÿ†” User Routes

  • POST /api/user/register - Register a new user.
  • POST /api/user/login - Login and receive an access token.

๐Ÿ”’ Protected Routes

  • GET /api/dashboard - Sample protected route (requires auth-token header).

๐Ÿ”‘ Environment Variables

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).

๐Ÿ“ฆ Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB (Mongoose)
  • Security: Jsonwebtoken, Bcrypt, Helmet, Cors
  • Validation: Joi

๐Ÿ“ License

This project is licensed under the ISC License.

About

๐Ÿƒ๐Ÿ“กRobust & Secure REST API for user authentication and authorization. Built with Node.js, Express, and MongoDB. Featuring JWT implementation, password hashing (Bcrypt), and data validation (Joi).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors