Skip to content
 
 

Repository files navigation

Authentication API

Node.js Express MongoDB JWT License

A secure REST API demonstrating user authentication and authorization using Node.js, Express, MongoDB, JWT, and bcrypt.

This project showcases modern backend authentication practices including password hashing, JSON Web Tokens, middleware-based route protection, and RESTful API development.


Features

  • User Registration
  • User Login
  • Password Hashing (bcrypt)
  • JWT Authentication
  • Protected Routes
  • MongoDB Integration
  • Express Middleware
  • Environment Variable Support

Technologies

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • JWT
  • bcrypt
  • dotenv

Project Structure

cohort-2-auth_last/
│
├── controllers/
├── middleware/
├── models/
├── routes/
├── server.js
├── package.json
└── README.md

Installation

Clone the repository

git clone https://github.com/RhemaGreat/cohort-2-auth_last.git

Install dependencies

npm install

Create a .env file

PORT=5000
MONGODB_URI=your_database_connection

ACCESS_TOKEN_SECRET=your_access_secret
REFRESH_TOKEN_SECRET=your_refresh_secret

Start the server

npm start

or

npm run dev

API Endpoints

Authentication

Method Endpoint Description
POST /register Register a new user
POST /login Authenticate a user
POST /logout Logout a user
GET /profile Protected user profile

Authentication

After successful login, include your access token:

Authorization: Bearer YOUR_ACCESS_TOKEN

Security Features

  • Password hashing using bcrypt
  • JWT Authentication
  • Protected routes
  • Environment variables
  • Middleware-based authorization

Learning Objectives

This project demonstrates:

  • REST API Development
  • Authentication
  • Authorization
  • JWT
  • Password Security
  • Express Middleware
  • MongoDB Integration
  • Backend Architecture

Future Improvements

  • Email Verification
  • Password Reset
  • Role-Based Access Control (RBAC)
  • Rate Limiting
  • Refresh Token Rotation
  • Swagger Documentation
  • Unit Testing
  • Docker Support
  • GitHub Actions
  • Two-Factor Authentication (2FA)

Contributing

Pull requests are welcome.


Roadmap

  • API Documentation
  • Unit Tests
  • Docker
  • CI/CD
  • RBAC
  • Refresh Token Rotation
  • Password Reset
  • Email Verification

Author

Rhema Great

GitHub: https://github.com/RhemaGreat


License

Licensed under the MIT License.

About

Secure authentication API built with Node.js, Express, MongoDB, JWT, and bcrypt, demonstrating user registration, login, and authorization best practices.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages