Skip to content
gem-plusPublic

About

JWT Authentication System built using MERN Stack with Access Token, Refresh Token, bcrypt, MongoDB, Express, React, and Tailwind CSS.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

MERN Authentication System

A MERN Stack authentication application implementing JWT-based authentication with Access Tokens and Refresh Tokens.

Features

  • User Registration
  • User Login
  • Password Hashing using bcrypt
  • JWT Authentication
  • Short-lived Access Token
  • Long-lived Refresh Token
  • Protected Dashboard Route
  • Refresh Token stored as HttpOnly Cookie
  • MongoDB Database
  • React Frontend
  • Express Backend

Tech Stack

Frontend

  • React
  • React Router
  • Tailwind CSS
  • Fetch API

Backend

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose
  • JWT
  • bcrypt

Folder Structure

Frontend

src/ ├── pages/ │ ├── auth.jsx │ ├── dashboard.jsx │ └── home.jsx

Backend

src/ ├── config/ ├── controllers/ ├── middleware/ ├── models/ ├── routes/ └── services/


Authentication Flow

  1. User registers.
  2. Password is hashed using bcrypt.
  3. User logs in.
  4. Server returns:
    • Access Token
    • Refresh Token (HttpOnly Cookie)
  5. Dashboard requests include Access Token.
  6. If Access Token expires, Refresh Token generates a new Access Token.

Installation

Backend

npm install
npm run dev

Frontend

npm install
npm run dev

Environment Variables

Backend

MONGO_URI=
JWT_SECRET=

Frontend

VITE_API_URL=http://localhost:5000

API Endpoints

POST /register

POST /login

GET /dashboard

GET /logout


Security

  • Password hashing with bcrypt
  • JWT Authentication
  • HttpOnly Refresh Token
  • Protected Routes

Future Improvements

  • Email Verification
  • Password Reset
  • Refresh Token Rotation
  • Role-based Authentication
  • Docker Deployment
  • Unit Testing

About

JWT Authentication System built using MERN Stack with Access Token, Refresh Token, bcrypt, MongoDB, Express, React, and Tailwind CSS.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages