A complete authentication system built with MERN stack (MongoDB, Express, React, Node.js) featuring:
- 🔑 Login / Signup
- ✅ Email Verification (via OTP)
- 🔄 Password Reset (via OTP)
- 🍪 JWT Auth with Secure Cookies
- 📧 Nodemailer Email Integration
- ⚛️ React Context for Auth State
/client → React frontend (Vite)
/server → Express backend
.env → Environment variables
README.md → You’re reading it :)
- User registration with hashed passwords (
bcrypt) - Login with JWT stored in HTTP-only secure cookies
- Email verification using OTP (One-Time Password)
- Forgot password flow with OTP + reset
- Nodemailer config for sending emails (Gmail or others)
- CORS-secure and production-ready
- Simple and beautiful UI (customizable)
| Layer | Technology |
|---|---|
| Frontend | React + Vite + Context API |
| Backend | Express.js + Node.js |
| Database | MongoDB + Mongoose |
| Auth | JWT + Cookies |
| Nodemailer |
- JWT tokens stored in
httpOnlycookies - Passwords hashed with
bcrypt - OTPs expire after a timeout
- Cookies configured with environment-aware
SameSiteandSecureattributes
- Add Google OAuth support
- Rate-limit OTP requests
- Add resend OTP functionality
- Add UI themes (Dark/Light)
-
Initial
userIdUndefined (Frontend):
Resolved by ensuring backend register/login responses includeduserIdin the JSON response and frontend accessed it properly. -
Authentication Middleware &
req.userMisalignment (Backend):
Fixed theuserAuthmiddleware to attachuserIdtoreq.userinstead ofreq.body, enabling/api/user/datato fetch correct user details.