This project is an advanced authentication system built using the MERN (MongoDB, Express, React, Node.js) stack. It includes features like email verification, secure password hashing, and token-based authentication.
The project is organized as follows:
- Root: Contains the main
package.json
file and links to both the backend and frontend folders. - backend: Contains the server-side code, including API endpoints, database models, and authentication logic.
- frontend: Contains the client-side code, built with React, for user interaction and UI.
- User registration and login
- Email verification using Mailtrap
- Secure password hashing with bcrypt
- Token-based authentication with JSON Web Tokens (JWT)
- Protected routes for authenticated users
- Responsive and user-friendly UI
- Frontend: React, Axios, Bootstrap/Material-UI (optional)
- Backend: Node.js, Express.js, MongoDB, Mongoose
- Authentication: JWT, bcrypt
- Email Service: Mailtrap
- Node.js and npm installed
- MongoDB installed and running
- Mailtrap account for email testing
-
Clone the repository:
git clone https://github.com/arafatDU/mern-advanced-auth.git cd mern-advanced-auth
-
Install dependencies for the root project:
npm install
-
Install dependencies for both backend and frontend:
cd backend npm install cd ../frontend npm install
-
Configure environment variables:
- Create a
.env
file in thebackend
folder with the following:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret MAILTRAP_USER=your_mailtrap_username MAILTRAP_PASS=your_mailtrap_password
- Create a
-
Start the development server:
npm run dev
This will start the backend server located at
backend/index.js
.
- Register a new user.
- Check your Mailtrap inbox for the verification email.
- Verify your email to activate your account.
- Log in to access protected routes.
mern-advanced-auth/
├── backend/
│ ├── controllers/
│ ├── db/
│ ├── routes/
│ ├── index.js
│ └── ...
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── utils/
│ │ └── App.js
├── package.json
└── README.md
This project is licensed under the MIT License.
- Mailtrap for email testing
- MERN Stack Documentation
Feel free to contribute to this project by submitting issues or pull requests!