π View it on Render
A complete full-stack MERN (MongoDB, Express, React, Node.js) authentication system with:
- β User registration & login
- β JWT authentication via HTTP-only cookies
- β Email verification using OTP
- β Password reset via OTP
- β Protected routes using middleware
- β Nodemailer integration
- Node.js
- Express
- MongoDB with Mongoose
- JWT (jsonwebtoken)
- Bcrypt
- Nodemailer
- dotenv
- React (Vite)
- Axios
- React Router DOM
- Tailwind CSS
- React Toastify
.
βββ client # React Frontend (Vite)
β βββ public
β βββ src
β βββ assets # Images/icons
β βββ components # Reusable UI components (Navbar, Header)
β βββ context # AppContext for global state
β βββ pages # Route pages (Login, Register, Verify, Reset)
βββ server # Node.js Backend
β βββ config # MongoDB config
β βββ controllers # Route controller logic
β βββ middlewares # JWT middleware (userAuth)
β βββ models # Mongoose models
β βββ routes # Express routers- π Registration & Login Secure password hashing with bcrypt
JWT token stored in HTTP-only cookies
Persistent login on refresh
- π§ Email Verification After register, user receives 6-digit OTP
User must verify their account
OTP expires after 24 hours
- π Password Reset User enters email to get OTP
OTP expires in 15 mins
After verifying OTP, user can reset password
- π‘οΈ Protected Routes Custom middleware (userAuth) to protect routes using token in cookies
- POST /api/auth/register β Register a new user
- POST /api/auth/login β Login existing user
- POST /api/auth/logout β Logout the current user
- POST /api/auth/send-verify-otp β Send email verification OTP
- POST /api/auth/verify-account β Verify user email using OTP
- GET /api/auth/is-auth β Check if user is authenticated
- POST /api/auth/send-reset-otp β Send password reset OTP to email
- POST /api/auth/reset-password β Reset password using OTP
- GET /api/user/data β Fetch authenticated user's data
Full-stack authentication using JWT and cookies
Building secure REST APIs with Express
Working with protected routes and middleware
Managing global app state using React Context API
Built using React, Node.js, Express, MongoDB
OTP via Nodemailer
Auth with JWT