Skip to content

πŸ” JWT Auth system using Access + Refresh Tokens with blacklist support on logout. Includes protected routes, httpOnly cookies, and token refresh logic using MongoDB and Express.

Notifications You must be signed in to change notification settings

jeevan42/jwt-auth-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JWT Auth Demo (Access + Refresh Token)

This project demonstrates a secure authentication system using JWT (access + refresh tokens) with blacklist support for logout.
It includes:

  • Signup & Login functionality
  • Get profile protected route functionality
  • JWT access token with expiry
  • Refresh token system using httpOnly cookie
  • Token blacklist on logout (to prevent reuse)
  • Protected route example (/profile)
  • MongoDB for user and blacklist token storage

πŸš€ Tech Stack

  • Node.js
  • Express.js
  • MongoDB + Mongoose
  • JWT (jsonwebtoken)
  • bcrypt
  • dotenv
  • cookie-parser
  • CORS

πŸ” Features

Feature Description
POST /auth/signup Register a new user
POST /auth/login Authenticate user and return access + refresh token
POST /auth/logout Invalidate current access token by blacklisting it
POST /auth/refresh-token Generate new access token using refresh token stored in httpOnly cookie
GET /auth/profile Access protected route (requires valid access token)

πŸ§ͺ How to Use (via Postman)

  1. Signup/Login
    ➀ Save the access token in localStorage (frontend)
    ➀ refresh token is auto-set in httpOnly cookie

  2. Access Protected Route
    ➀ Pass access token in Authorization: Bearer <token> header

  3. On Expired Access Token
    ➀ Call /auth/refresh-token to get a new access token
    ➀ Replace old access token in localStorage

  4. Logout
    ➀ Calls /auth/logout and blacklists the current token

πŸ“¬ Author

Developed by @jeevan42 πŸ”₯
Feel free to fork & use!


About

πŸ” JWT Auth system using Access + Refresh Tokens with blacklist support on logout. Includes protected routes, httpOnly cookies, and token refresh logic using MongoDB and Express.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published