Skip to content

πŸ”A MERN stack authentication system that includes user registration, login, and JWT-based session management with secure handling of passwords and token cookies. Ideal for building secure, scalable web applications.

License

Notifications You must be signed in to change notification settings

Fingertips18/mern-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

55 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Banner

πŸ”’ MERN-Auth

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

πŸ“š Table of Contents

  • 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.

πŸ› οΈ Backend (Express JS)

  1. Clone the repository:

    git clone https://github.com/Fingertips18/mern-auth.git
  2. Install dependencies:

    npm install
  3. 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>
  4. Run the backend server:

    npm run dev

βš›οΈ Frontend (React JS)

  1. Navigate to the frontend directory:

    cd frontend
  2. Install dependencies:

    npm install
  3. Set up environment variables. Create a .env.local file in the frontend directory:

    VITE_BASE_URL=<VITE_BASE_URL>
  4. 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.

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!

πŸ§‘β€πŸ’» Contributors

Ghian Tan @ Fingertips (Github)

This project is licensed under the MIT License.

About

πŸ”A MERN stack authentication system that includes user registration, login, and JWT-based session management with secure handling of passwords and token cookies. Ideal for building secure, scalable web applications.

Topics

Resources

License

Stars

Watchers

Forks