A lightweight Node.js + Express authentication app with a React login UI, email OTP verification, JWT cookie auth, and basic user management.
- User registration with password hashing
- Email OTP verification flow
- Login and logout with an HTTP-only JWT cookie
- MongoDB user model and CRUD API
- Email sending for OTP delivery
- Responsive React authentication UI
- Node.js, Express, MongoDB, Mongoose
- JWT, bcryptjs, Nodemailer
- React + Vite
Install dependencies for both apps:
cd server
npm install
cd ../client
npm installCopy server/.env.example to server/.env and set your database, JWT, and email credentials. Copy client/.env.example to client/.env if your API is not running at http://localhost:3000.
Run each app in its own terminal:
cd server
npm run devcd client
npm run devThe API runs at http://localhost:3000 and the UI at http://localhost:5173. Set the backend's CLIENT_URL to the UI origin so browser requests can include the authentication cookie.
POST /auth/register— register user and send OTPPOST /auth/verify-email— verify email with OTPPOST /auth/login— log in and set JWT cookiePOST /auth/logout— clear auth cookie
GET /users— get all usersGET /users/:id— get one userPUT /users/:id— update userDELETE /users/:id— delete user
client/
├── src/
│ ├── App.jsx
│ ├── main.jsx
│ └── styles.css
├── .env.example
├── index.html
└── vite.config.js
server/
├── config/
├── controller/
├── middleware/
├── models/
├── routes/
├── utils/
├── index.js
├── package.json
└── .env.example