This repository features a MERN stack authentication system, encompassing user registration, login, and JWT-based session management. It securely handles passwords and token cookies, making it an excellent foundation for building secure and scalable web applications.
🔗 Website Link: Live
- 🔧 Technologies Used
- ✨ Features
- 📖 Setup Instructions
- 🐍 Backend (Express JS)
- ⚛️ Frontend (React JS)
- 📡 API Endpoints
- 🔒 Authentication
- 🤝 Contributing
- 📜 License
- Frontend: React JS ⚛️
- Backend: Express JS 🐍
- Database: MongoDB 🗄️
- Authentication: JWT (JSON Web Tokens) 🔐
- Email Service: Mailtrap 📫
✨ Features
- 🔒 User Authentication: Comprehensive authentication system including sign-up, login, sign-out, and JWT-based session management.
- ✉️ Email Verification: Integrated Mailtrap for managing email verification and password reset workflows.
- 🔑 Password Management: Secure handling of forgot password, reset password, and reset verification workflows.
- 📝 CRUD Operations: Create, Read, Update, and Delete operations for user and application data.
- 📱 Responsive UI: Developed using React components, ensuring a seamless experience across devices.
- 📡 API: Robust API constructed using Express.js and MongoDB for seamless data interaction.
-
Clone the repository:
git clone https://github.com/Fingertips18/mern-auth.git
-
Install dependencies:
npm install
-
Set up environment variables. Create a
.env
file in the root directory::PORT=<PORT> MONGO_URI=<MONGO_URI> JWT_SECRET=<JWT_SECRET> NODE_ENV=<NODE_ENV> EMAILJS_SERVICE_ID=<EMAILJS_SERVICE_ID> EMAILJS_TEMPLATE_ID=<EMAILJS_TEMPLATE_ID> EMAILJS_PUBLIC_KEY=<EMAILJS_PUBLIC_KEY> EMAILJS_PRIVATE_KEY=<EMAILJS_PRIVATE_KEY> CLIENT_URL=<CLIENT_URL>
-
Run the backend server:
npm run dev
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Set up environment variables. Create a
.env.local
file in the frontend directory:VITE_BASE_URL=<VITE_BASE_URL>
-
Run the frontend server:
npm run dev
-
Root:
GET /
: The root of the server
-
Authentication:
-
POST
/api/auth/sign-up : Register a new user. -
POST
/api/auth/sign-in : Log in a user and return a JWT. -
POST
/api/auth/sign-out : Log out a user and clear the session. -
POST
/api/auth/verify-email : Verify a user's email address. -
POST
/api/auth/forgot-password : Send a password reset email. -
POST
/api/auth/reset-password : Reset a user's password. -
GET
/api/auth/verify-token : Verify the validity of a JWT.
-
This project uses JWT for secure authentication. Tokens are stored in cookies with HttpOnly
and SameSite
attributes for enhanced security.
Both the frontend
and backend
handle the verification and expiration of the token.
Feel free to fork this repository and contribute by submitting a pull request. All contributions are welcome!
Ghian Tan @ Fingertips (Github)
This project is licensed under the MIT License.