A full-stack authentication platform built with the MERN stack (MongoDB, Express.js, React, and Node.js). The application provides a secure and modern authentication workflow, including account registration, email verification, password recovery, JWT-based authentication, and protected routes.
- User registration
- User login and logout
- JWT authentication
- Secure password hashing with bcrypt
- Protected API routes
- Authentication state management
- Verification code generation
- Email account confirmation
- Verification token expiration handling
- Welcome email after successful verification
- Forgot password functionality
- Secure password reset tokens
- Password reset expiration validation
- Password reset confirmation email
- Password hashing using bcrypt
- JWT token-based authentication
- HTTP-only cookie support
- Secure token generation
- Input validation
- Environment variable configuration
- User profile retrieval
- Authentication status checking
- Last login tracking
- Account verification status
- React
- Vite
- JavaScript
- Axios
- React Router
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT
- bcryptjs
- Cookie Parser
- Mailtrap
SecureAuth-MERN/
│
├── backend/
│ ├── controllers/
│ ├── middleware/
│ ├── models/
│ ├── routes/
│ ├── mailtrap/
│ ├── utils/
│ └── server.js
│
├── frontend/
│ ├── public/
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── store/
│ │ └── utils/
│ └── vite.config.js
│
├── .env
├── package.json
└── README.md
Create a .env file inside the backend directory and configure the following variables:
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
CLIENT_URL=http://localhost:5173
MAILTRAP_TOKEN=your_mailtrap_token
MAILTRAP_ENDPOINT=your_mailtrap_endpoint
NODE_ENV=developmentgit clone https://github.com/Pa004/SecureAuth-MERN.git
cd SecureAuth-MERNnpm installInstall frontend dependencies:
cd frontend
npm installStart the backend server:
npm run devStart the frontend application:
cd frontend
npm run devBuild the frontend:
cd frontend
npm run buildRun the application:
npm start- User creates an account.
- A verification code is sent via email.
- User verifies the account.
- User can log in securely.
- JWT token is generated and stored.
- Protected routes become accessible.
- Password recovery is available if needed.
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/signup |
Register a new user |
| POST | /api/auth/login |
Authenticate user |
| POST | /api/auth/logout |
Logout user |
| POST | /api/auth/verify-email |
Verify email address |
| POST | /api/auth/forgot-password |
Request password reset |
| POST | /api/auth/reset-password/:token |
Reset password |
| GET | /api/auth/check-auth |
Check authentication status |
- Passwords are never stored in plain text.
- Authentication tokens are securely generated.
- Password reset links have expiration times.
- Email verification codes expire automatically.
- Sensitive information is stored in environment variables.
- Protected routes require valid authentication.
- Role-based access control (RBAC)
- Multi-factor authentication (MFA)
- OAuth integration (Google, GitHub)
- Refresh token support
- User profile management
- Automated testing
- Docker deployment
- CI/CD pipeline integration
This project is intended for educational and development purposes.