A full-stack authentication system with user registration, login, email verification, password reset, and protected routes. Built with React (Vite) frontend and Node.js/Express/MongoDB backend.
- User registration and login
- Email verification (with OTP)
- Password reset via email OTP
- JWT-based authentication
- Protected routes
- React Context for global state
- Toast notifications for feedback
- Frontend: React, Vite, Tailwind CSS
- Backend: Node.js, Express.js, MongoDB (Mongoose)
- Email: Nodemailer (Gmail SMTP or Brevo/Sendinblue)
client/ # React frontend
src/
assets/ # Images and icons
components/ # Reusable UI components
context/ # React Context (AppContext)
pages/ # Page components (Login, Home, etc.)
...
server/ # Node.js backend
controllers/ # Route controllers (auth, user)
models/ # Mongoose models
routes/ # Express routes
config/ # Config files (db, nodemailer)
middleware/ # Auth middleware
...
- Node.js and npm
- MongoDB (local or Atlas)
git clone https://github.com/hanisx019/Auth-System.git
cd Auth-System
cd server
npm install
- Create a
.envfile inserver/with:PORT=5000 MONGODB_URL=mongodb://localhost:27017 JWT_SECRET=your_jwt_secret NODE_ENV=development SMTP_USER=your_email@gmail.com SMTP_PASS=your_gmail_app_password SENDER_EMAIL=your_email@gmail.com - Start the backend:
npm start
cd ../client
npm install
- Create a
.envfile inclient/with:VITE_BACKEND_URL=http://localhost:5000 - Start the frontend:
npm run dev
- Visit
http://localhost:5173in your browser. - Register a new user, verify email, login, and test password reset.
- Backend:
PORT: Backend server portMONGODB_URL: MongoDB connection stringJWT_SECRET: Secret for JWTSMTP_USER/SMTP_PASS: Email credentials (Gmail App Password recommended)SENDER_EMAIL: Sender email address
- Frontend:
VITE_BACKEND_URL: Backend API URL
- For Gmail SMTP, enable 2FA and use an App Password.
- For production, use environment variables securely and update CORS settings.
MIT