A full-featured MERN Stack (MongoDB, Express, React, Node.js) project with secure authentication, authorization, and role-based access control. Users can signup/login to explore your portfolio. Protected backend APIs and frontend routes ensure only authorized access.
- JWT Auth System with secure token storage
- Login / Signup routes with validation using
Joi - Protected APIs with JWT Middleware
- MongoDB for storing user data securely
- Frontend in React with routing and
react-toastify - Form validation, redirect, and localStorage handling
MERN5/
├── backend/
│ ├── Controllers/
│ ├── Middlewares/
│ ├── Models/
│ ├── Routes/
│ ├── db.js
│ ├── .env
│ └── index.js
├── frontend/
│ ├── public/
│ └── src/
│ ├── pages/
│ ├── login.css
│ └── utils.js
- Initializes Express
- Sets up CORS, JSON parsing
- Connects to MongoDB
- Loads
authandproductroutes
- MongoDB connection using
mongoose - Uses
.envvariableMONGO_CONN
PORT=8080
MONGO_CONN=your_mongo_url
JWT_SECRET=your_secret
-
signup()- Hashes password with
bcrypt - Checks duplicate user
- Saves user to MongoDB
- Hashes password with
-
login()- Validates credentials
- Sends back
jwtToken,name,email
name: String,
email: String (unique),
password: String- Verifies JWT from
Authorizationheader - Attaches decoded user to
req.user
- Validates inputs using Joi schema
- Blocks bad requests with status
400
POST /auth/signup // Validates + Creates user
POST /auth/login // Validates + Authenticates userGET /products // Protected routeReturns an array of product items only when a valid JWT is provided.
- Form to collect name, email, password
- On submit, makes
POST /auth/signup - Stores
jwtTokenin localStorage - Redirects to
/home
- Collects email & password
- Makes
POST /auth/login - On success, saves token and username to localStorage
- Redirects to protected page
- Reusable, clean UI for signup & login forms
handleSuccess(msg); // shows green toast
handleError(msg); // shows red toastcd backend
npm install
echo PORT=8080 > .env
echo MONGO_CONN=your_mongo_url >> .env
echo JWT_SECRET=your_secret_key >> .env
node index.jscd frontend
npm install
npm start| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /auth/signup | Create user | No |
| POST | /auth/login | Get JWT Token | No |
| GET | /products | Get product list | Yes |
Saurabh Singh Rajput 2nd Year CSE @ IIIT Bhagalpur Self-Taught MERN Stack Developer 🤝
- Add user profile route
- Build admin dashboard
- Integrate Google OAuth
- Password reset via email
If you liked this project, consider giving a ⭐ on GitHub!