Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User-Login

🚀 Production-Grade Auth Backend (Node.js & MongoDB) A high-performance, secure backend architecture built with Node.js, Express, and MongoDB Atlas. This project implements professional-grade authentication using JWT (Access & Refresh Tokens), Bcrypt password hashing, and a centralized Middleware-Controller pattern.

🛠️ Tech Stack & Tools Runtime: Node.js

Framework: Express.js

Database: MongoDB Atlas (Mongoose ODM)

Authentication: JSON Web Tokens (JWT)

Security: Bcrypt.js (Password Hashing), CORS, Cookie-Parser

Development: Nodemon, Dotenv

🏗️ Architectural Overview The project follows the MVC (Model-View-Controller) pattern for clean separation of concerns:

Models: Defines the data structure and Mongoose hooks (pre-save hashing).

Routes: Manages API endpoints and applies middleware.

Controllers: Contains the core business logic (Register, Login, Logout).

Utils: Centralized classes for standardized API Responses and Error Handling.

Middleware: Custom logic for JWT verification and async error wrapping.

🔐 Key Features

  1. Secure Authentication Flow Uses a dual-token system for maximum security:

Short-lived Access Tokens: For immediate authorization.

Long-lived Refresh Tokens: Stored in the database and sent via HttpOnly Cookies to prevent XSS attacks.

  1. Password Protection Uses bcrypt to hash passwords before saving them to the database. Even if the database is compromised, user passwords remain encrypted.

  2. Centralized Error Handling A custom ApiError class ensures that every error (404, 401, 500) returns a consistent JSON format, making frontend integration seamless.

About

first backend project

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages