A full-stack authentication web application built with the MERN stack (MongoDB, Express, React, Node.js). It supports user registration, login, protected routes, and session management using localStorage.
| Service | URL |
|---|---|
| Frontend | auth-app-frontend-d0e5.onrender.com |
| Backend | auth-app-backend-ou86.onrender.com |
auth-app/
βββ client/ # React Frontend (Vite)
β βββ public/
β βββ src/
β β βββ components/
β β β βββ Welcome.jsx # Landing page
β β β βββ LoginPage.jsx # Login form
β β β βββ SignupPage.jsx # Signup form
β β β βββ MainPage.jsx # Protected dashboard
β β β βββ ProtectedRoute.jsx # Route guard
β β β βββ NotFound.jsx # 404 page
β β βββ App.jsx # Route definitions
β β βββ main.jsx # React entry point
β β βββ index.css
β βββ index.html
β βββ package.json
β
βββ server/ # Express Backend
βββ controllers/
β βββ loginController.js # Login logic
β βββ signupController.js # Signup logic
βββ db/
β βββ dbConnect.js # MongoDB connection
βββ models/
β βββ userModel.js # Mongoose user schema
βββ routes/
β βββ userRoutes.js # API route definitions
βββ index.js # Express app entry point
βββ package.json
| Technology | Version | Purpose |
|---|---|---|
| React | 19.x | UI library |
| Vite | 7.x | Build tool & dev server |
| React Router DOM | 7.x | Client-side routing |
| Axios | 1.x | HTTP requests |
| Tailwind CSS | 4.x | Utility-first styling |
| React Icons | 5.x | Icon components |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | LTS | Runtime environment |
| Express | 5.x | Web framework |
| MongoDB | β | NoSQL database |
| Mongoose | 9.x | ODM for MongoDB |
| bcrypt | 6.x | Password hashing |
| dotenv | 17.x | Environment variable management |
| CORS | 2.x | Cross-origin resource sharing |
git clone https://github.com/your-username/auth-app.git
cd auth-appcd server
npm installCreate a .env file in the server/ directory:
MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/
PORT=3000Start the backend server:
npm startThe server runs at http://localhost:3000.
cd client
npm installNote: The API base URL is currently hardcoded in
LoginPage.jsxandSignupPage.jsx.
For local development, update theaxios.postURLs from the production backend tohttp://localhost:3000.
Start the development server:
npm run devThe frontend runs at http://localhost:5173.
Base URL: https://auth-app-backend-ou86.onrender.com/api
Register a new user.
Request Body:
{
"user_name": "John Doe",
"email": "john@example.com",
"password": "yourpassword"
}Responses:
| Status | Description |
|---|---|
201 |
User registered successfully |
409 |
Email already exists |
500 |
Internal server error |
Success Response:
{
"user_name": "John Doe",
"success": true,
"message": "user sign up successfully"
}Authenticate an existing user.
Request Body:
{
"email": "john@example.com",
"password": "yourpassword"
}Responses:
| Status | Description |
|---|---|
200 |
Login successful |
401 |
Incorrect password |
404 |
Email not found |
500 |
Internal server error |
Success Response:
{
"user_name": "John Doe",
"success": true,
"message": "Login successful"
}Collection: users (inside authDB)
| Field | Type | Constraints |
|---|---|---|
user_name |
String | Required |
email |
String | Required, Unique, Lowercase |
password |
String | Required, Hashed (bcrypt, salt rounds: 10) |
createdAt |
Date | Auto-generated (timestamps) |
updatedAt |
Date | Auto-generated (timestamps) |
Passwords are hashed automatically via a Mongoose
pre('save')middleware before being stored.
| Route | Component | Access |
|---|---|---|
/ |
Welcome |
Public |
/login |
LoginPage |
Public |
/signup |
SignupPage |
Public |
/mainpage |
MainPage |
π Protected |
* |
NotFound |
Public (404) |
ProtectedRoute.jsx checks for isLoggedIn in localStorage. If the value is absent, the user is redirected to /login.
User visits /signup
βββ Submits form β POST /api/users/signup
βββ On success β localStorage.setItem("isLoggedIn", "true")
β localStorage.setItem("user_name", ...)
β Navigate to /mainpage
User visits /login
βββ Submits form β POST /api/users/login
βββ On success β localStorage.setItem("isLoggedIn", "true")
β localStorage.setItem("user_name", ...)
β Navigate to /mainpage
User clicks Logout (MainPage)
βββ localStorage.removeItem("isLoggedIn")
βββ localStorage.removeItem("user_name")
βββ Navigate to /login
| Script | Command | Description |
|---|---|---|
| Dev server | npm run dev |
Start Vite dev server |
| Build | npm run build |
Production build |
| Preview | npm run preview |
Preview production build |
| Lint | npm run lint |
Run ESLint |
| Script | Command | Description |
|---|---|---|
| Start | npm start |
Run with Node.js |
This project is licensed under the ISC License.
Built with β€οΈ using the MERN stack.