A production-ready MERN stack authentication system with secure JWT & refresh token handling, role-based access control, and a modern React + TailwindCSS frontend.
- π MERN Stack (MongoDB, Express, React, Node.js)
- π Authentication & Authorization
- Login, Logout
- Access & Refresh Tokens
- Secure password hashing with bcrypt
- π‘οΈ Protected Routes (API + Frontend)
- π¨ Modern UI with React + TailwindCSS
- πͺ Cookie-based sessions with HttpOnly cookies
- π Clean and maintainable folder structure
Frontend: React, Vite, TailwindCSS
Backend: Node.js, Express.js, MongoDB, Mongoose
Auth: JWT, Refresh Tokens, bcrypt
Dev Tools: Nodemon, dotenv
git clone https://github.com/your-company/mern-auth-boilerplate.git
cd mern-auth-boilerplatecd backend
npm installCreate a .env file inside /backend:
PORT=3000
MONGODB_URI=your_mongodb_connection_string
DB_NAME=authdb
ACCESS_TOKEN_SECRET=your_access_secret
ACCESS_TOKEN_EXPIRY=1d
REFRESH_TOKEN_SECRET=your_refresh_secret
REFRESH_TOKEN_EXPIRY=15d
CORS_ORIGIN=http://localhost:5173Run backend server:
npm run devcd frontend
npm install
npm run devThe frontend runs on http://localhost:5173
The backend runs on http://localhost:3000
- Open frontend in browser (
http://localhost:5173) - Register / Login with email & password
- Access protected dashboard with JWT auth
mern-auth-boilerplate/
βββ backend/
β βββ routes/
β βββ controllers/
β βββ models/
β βββ middleware/
β βββ server.js
β
βββ frontend/
β βββ src/
β β βββ components/
β β βββ pages/
β β βββ context/
β β βββ App.jsx
β βββ tailwind.config.js
β
βββ README.md
This project is maintained by onescreensolutions.
Feel free to use it for learning or as a starting point for production projects.
Pull requests are welcome. For major changes, please open an issue first to discuss what youβd like to change.
This repository is maintained by onescreensolutions as a standard authentication boilerplate for production-ready MERN applications.