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
π§ Technologies Used
- 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.
π Setup Instructions
π οΈ Backend (Express JS)
-
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
βοΈ Frontend (React JS)
-
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
π‘ API Endpoints
-
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.
-
π Authentication
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.
π€ Contributing
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.