Skip to content

πŸ” Advanced MERN Authentication System | πŸš€ Secure user login, registration, and password management with modern UI enhancements.

License

Notifications You must be signed in to change notification settings

mhdZhHan/advanced-mern-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Advanced MERN Authentication

Welcome to the Advanced MERN Authentication! This project provides a robust authentication system built with the MERN (MongoDB, Express, React, Node.js) stack. It includes essential features like user registration, login, logout, email verification, and password management.

🌟 Features

  • πŸ”’ Check Authentication (/check-auth): Verify if the user is authenticated.
  • πŸ“ Sign up (/signup): Register a new user account.
  • πŸ” Login (/login): Authenticate and log in a user.
  • πŸšͺ Logout (/logout): Log out the user by invalidating the session/token.
  • πŸ“§ Email Verification (/verify-email): Verify a user's email address.
  • πŸ”‘ Forgot Password (/forgot-password): Initiate the password reset process.
  • πŸ”„ Reset Password (/reset-password/:token): Reset the user's password using a secure token.
  • πŸͺ Generate Token and Set Cookie: Creates a JWT token and securely sets it in a cookie.
  • πŸš€ Frontend Pages: Includes frontend pages such as Sign Up, Login, Dashboard, Forgot Password, Reset Password, and Email Verification.
  • πŸ“¦ State Management: The project uses Zustand for state management to handle user authentication state.
  • ⚑ API Integration: Axios is used for seamless integration with the authentication API.
  • 🎨 UI Enhancements: Tailwind CSS is used for modern and responsive styling, while Framer Motion adds smooth animations and transitions for a dynamic user experience.

πŸ› οΈ Installation

Clone the repository:

git clone https://github.com/mhdZhHan/advanced-mern-auth.git
cd advanced-mern-auth

Install dependencies and build the app:

npm run build

Set up environment variables:

Create a .env file in the root directory and add the following variables:

MONGODB_URL="" # MongoDB connection string
JWT_SECRET="" # Secret key for JWT signing
NODE_ENV="development" # Set to "production" in a live environment
MAILTRAP_TOKEN="" # Mailtrap API token for sending emails
MAILTRAP_ENDPOINT="" # Mailtrap API endpoint for email services
CLIENT_URL="http://localhost:5173" # URL of the React frontend application

Run the application:

npm run start

Your server should now be running on http://localhost:5000.

πŸ”— API Endpoints

The authentication-related API endpoints are available under the /api/auth base URL. Here are the available routes:

  • GET /api/auth/check-auth: Verifies if the user is authenticated by checking the token.
  • POST /api/auth/signup: Registers a new user and sends an email verification link.
  • POST /api/auth/login: Logs in the user and returns a JWT token.
  • POST /api/auth/logout: Logs out the user by clearing the session.
  • POST /api/auth/verify-email: Verifies the user's email address with a token.
  • POST /api/auth/forgot-password: Sends a password reset link to the user's email.
  • POST /api/auth/reset-password/:token: Resets the user's password using the provided token.

πŸš€ Technologies Used

  • MongoDB: Database for storing user information.
  • Express: Web framework for handling routes and middleware.
  • React: Frontend framework for creating the client-side application (not included in this repo).
  • Node.js: Backend runtime environment.
  • JSON Web Tokens (JWT): For secure user authentication.
  • Mailtrap: Service for sending emails (used for email verification and password reset).
  • Zustand: State management library for handling user authentication state.
  • Axios: HTTP client for making API requests.
  • Tailwind CSS: Utility-first CSS framework for modern and responsive styling.
  • Framer Motion: Library for adding smooth animations and transitions for enhanced UI interactions.

About

πŸ” Advanced MERN Authentication System | πŸš€ Secure user login, registration, and password management with modern UI enhancements.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages