Skip to content

Built a production-ready MERN authentication system with JWT, email OTP verification, password reset flow, and secure cookie-based sessions, deployed on Vercel and Render.

Notifications You must be signed in to change notification settings

amit77t/AuthenticationSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

πŸ” MERN Authentication System

Login, Registration & Password Reset using JWT + Email OTP Verification

A complete authentication system built with the MERN Stack featuring secure JWT-based authentication, email verification using OTP, password reset flow, and protected routes.
This project demonstrates real-world authentication architecture used in production applications.


πŸš€ Live Demo


πŸ“Έ Screenshots

πŸ“Œ Add images inside a screenshots/ folder

  • 🏠 Home Page
    Screenshot (91)

  • πŸ”‘ Login Page
    Screenshot (93)

  • πŸ“ Register Page
    Screenshot (92)

  • πŸ” Password Reset
    Screenshot (94)


✨ Features

  • βœ… User Registration with Email & Password
  • βœ… Secure Login using JWT Authentication
  • βœ… Email Verification via OTP (NodeMailer + Brevo SMTP)
  • βœ… Forgot Password & Reset Password using OTP
  • βœ… HTTP-Only Cookies for JWT (XSS Protection)
  • βœ… Protected Routes (Backend Middleware)
  • βœ… Context API for Global Auth State
  • βœ… Fully Responsive UI (Tailwind CSS)
  • βœ… Production-ready deployment (Render + Vercel)

πŸ› οΈ Tech Stack

Frontend

  • βš›οΈ React (Vite)
  • 🌐 Axios
  • 🧠 Context API
  • 🎨 Tailwind CSS
  • πŸ”” React Toastify

Backend

  • 🟒 Node.js
  • πŸš€ Express.js
  • πŸƒ MongoDB + Mongoose
  • πŸ” JWT Authentication
  • πŸ”‘ bcrypt.js (Password Hashing)
  • βœ‰οΈ NodeMailer (Email OTP)
  • πŸͺ Cookie Parser
  • 🌍 CORS Configuration

🌍 Deployment

  • Frontend β†’ Vercel
  • Backend β†’ Render
  • Database β†’ MongoDB Atlas

πŸ” Authentication Flow

πŸ“ Registration

  1. User signs up with name, email, password
  2. Password hashed using bcrypt
  3. JWT generated and stored in HTTP-only cookie
  4. Verification OTP sent via email

πŸ“© Email Verification

  1. OTP sent to registered email
  2. OTP validated with expiry check
  3. Account marked as verified

πŸ”‘ Login

  1. Credentials validated
  2. JWT generated and stored securely
  3. User session maintained via cookies

πŸ” Password Reset

  1. User requests reset via email
  2. OTP sent to email
  3. OTP verified
  4. Password updated securely

πŸ“‚ Project Structure

AuthenticationSystem/
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ config/
β”‚   └── server.js
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── assets/
β”‚   └── main.jsx
β”‚
└── README.md

βš™οΈ Environment Variables

Backend (Render)

MONGODB_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret
NODE_ENV=production

SMTP_USER=your_smtp_user
SMTP_PASS=your_smtp_password
SENDER_EMAIL=your_email

Frontend (Vercel)

VITE_BACKEND_URL=https://authenticationsystem-illr.onrender.com

πŸ§ͺ Run Locally

Clone the repository

git clone https://github.com/amit77t/AuthenticationSystem.git cd AuthenticationSystem

Backend Setup


cd backend
npm install
npm run server

Frontend Setup

cd frontend
npm install
npm run dev

πŸ”’ Security Highlights

  • πŸ” Password hashing with bcrypt

  • πŸͺ HTTP-only JWT cookies

  • 🌍 Strict CORS configuration

  • ⏱ OTP expiration handling

  • 🚫 Sensitive data stored in environment variables

πŸ“Œ Future Improvements

  • πŸ”„ Refresh Token implementation

  • πŸ“± Google / GitHub OAuth

  • πŸ§‘β€πŸ’Ό User Dashboard

  • πŸ§ͺ Unit & Integration Testing

  • πŸ” Role-based Authorization

πŸ‘¨β€πŸ’» Author

Amit Chaurasia

⭐ Support

  • If you like this project:

  • ⭐ Star the repository

  • 🍴 Fork it

  • πŸ“’ Share it

About

Built a production-ready MERN authentication system with JWT, email OTP verification, password reset flow, and secure cookie-based sessions, deployed on Vercel and Render.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages