An open API service indexing awesome lists of open source software.

https://github.com/hackur45/secure-backend

๐Ÿ” A secure Node.js + Express backend with JWT authentication, email verification, password reset, and protected routes. Built with MongoDB, tested with Postman, and ready for frontend integration.
https://github.com/hackur45/secure-backend

backend express-middleware express-session jwt-authentication mongo nodejs nodemailer

Last synced: about 2 months ago
JSON representation

๐Ÿ” A secure Node.js + Express backend with JWT authentication, email verification, password reset, and protected routes. Built with MongoDB, tested with Postman, and ready for frontend integration.

Awesome Lists containing this project

README

          

# ๐Ÿ” Secure Auth Backend

A secure, scalable, and testable backend application built with **Express.js** and **MongoDB Atlas**. Includes authentication with email-based verification, password reset, rate limiting, and unit testing.

---

## ๐Ÿš€ Features

- โœ… User Registration with Email Verification (Nodemailer)
- ๐Ÿ” Secure Login with JWT
- โ™ป๏ธ Email-based Password Reset Flow
- โš™๏ธ Rate Limiting with `express-rate-limit`
- ๐Ÿงช Unit Testing with Jest + Supertest
- โ›” Prevents Simultaneous Logins
- ๐Ÿ›ก๏ธ Environment Variables via `.env`
- ๐ŸŒ MongoDB Atlas Integration

---

## ๐Ÿ“ฆ Tech Stack

- Node.js
- Express.js
- MongoDB (Atlas)
- Mongoose
- Nodemailer (Gmail App Password)
- dotenv
- express-rate-limit
- Jest + Supertest

---

## ๐Ÿ— Backend Architecture

![Backend Architecture](diagram.png)

The backend architecture includes:
- Express.js server handling API requests.
- MongoDB Atlas for data persistence.
- JWT-based authentication for secure access.
- Email services for verification and password reset.
- Middleware for authentication and rate limiting.

---

## ๐Ÿ›  Setup Instructions

### 1. Clone the Repo
```bash
git clone https://github.com/Hackur45/secure-backend.git
cd secure-backend
```

### 2. Install Dependencies

```bash
npm install
```

### 3. Create `.env` File

```env
PORT=5500
MONGO_URI=your_mongo_connection_string
JWT_SECRET=your_jwt_secret
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password
```

### 4. Start Server

```bash
npm start
```

Server runs on `http://localhost:5500`

---

## ๐Ÿ“ฎ API Endpoints and Utilities

### ๐Ÿ”น POST /api/register
Registers a new user by accepting an email address. Sends a verification email with a token to confirm the user's email address.
*See Postman Screenshot:*![alt text]()

### ๐Ÿ”น POST /api/verify-registration
Verifies the user's email using the token sent via email and sets the user's password. Marks the account as verified.
*See Postman Screenshot:*![alt text]()
![alt text]()

### ๐Ÿ”น POST /api/login
Authenticates a user with email and password. Returns a JWT token upon successful login for session management.
*See Postman Screenshot:*![alt text]()

### ๐Ÿ”น POST /api/request-password-reset
Initiates a password reset by generating a reset token and sending a reset email to the user.
*See Postman Screenshot:*![alt text]()

### ๐Ÿ”น POST /api/reset-password
Resets the user's password using the valid reset token and new password provided.
*See Postman Screenshot:*![alt text]()

### ๐Ÿ”’ GET /api/dashboard
A protected route that requires a valid Bearer token (JWT). Returns a welcome message and the authenticated user's ID.
*See Postman Screenshot:*![alt text]()

---

## ๐Ÿงช Running Tests

```bash
npm test
```

Runs unit tests using Jest + Supertest.

---

## โš ๏ธ Notes

* Use Gmail App Passwords (not your main password) for Nodemailer.
* Reset token and verification token are time-limited and secure.
* Rate limiting protects against abuse on login and registration routes.

Please refer the `Postman teting Routes.txt` file for more clarification about the routes.

## ๐Ÿ™Œ Contribute

As always, I'm a bit lazy when it comes to the frontend โ€” so if you're up for it, **feel free to contribute**! I'd love to see a minimal UI built for these authentication routes.

This repository is **MIT licensed** and open to all.
Pull requests are welcome!

Happy Coding! ๐Ÿ˜€