jwt-auth

Implement JWT authentication with httpOnly cookies and token rotation for MERN applications.

1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/chavangorakh1999/sde-skills --skill jwt-auth-chavangorakh1999
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jwt-auth
Source: https://github.com/chavangorakh1999/sde-skills/tree/main/mern-stack/skills/jwt-auth
Command: npx skills add https://github.com/chavangorakh1999/sde-skills --skill jwt-auth-chavangorakh1999

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill provides a robust and secure implementation for handling JSON Web Token (JWT) authentication in MERN (MongoDB, Express, React, Node.js) applications, covering the full lifecycle from registration to logout.

Core Features & Use Cases

  • Full Auth Flow: Implements registration, login, access token generation, refresh token management (with httpOnly cookies and rotation), and server-side logout.
  • Security Best Practices: Incorporates password hashing (bcrypt), token rotation, reuse detection, and secure cookie settings.
  • Use Case: Integrate this Skill into your new MERN application to quickly establish a secure authentication system, protecting user data and ensuring proper session management.

Quick Start

Implement the complete JWT authentication flow for a MERN application.

Frequently Asked Questions about jwt-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement JWT authentication in a MERN stack application?

JWT authentication in a MERN stack application is implemented by generating access and refresh tokens, storing refresh tokens in httpOnly cookies, and rotating tokens upon use. This Skill provides the complete flow from registration to secure server-side logout.

What is refresh token rotation and reuse detection in JWT auth?

Refresh token rotation in JWT auth issues a new refresh token with each access token request, while reuse detection invalidates the session if a previously rotated token is reused. This approach prevents token theft and secures user sessions in MERN applications.

How should I securely store JWTs in React and Node.js?

Securely store JWTs in React and Node.js by placing refresh tokens in httpOnly cookies to prevent JavaScript access, and using short-lived access tokens. This Skill implements that pattern with bcrypt for password hashing and SHA-256 for refresh token hashing.

Does this JWT auth implementation handle server-side logout?

Yes, this JWT auth implementation handles server-side logout by invalidating the stored refresh token. It ensures that even if the httpOnly cookie is compromised, the refresh token cannot be reused to generate new access tokens after the user logs out.

What is the best way to hash passwords in a MERN stack application?

The best way to hash passwords in a MERN stack application is using bcrypt for secure salted hashing. This Skill incorporates bcrypt for password storage alongside SHA-256 for refresh token hashing to ensure robust authentication security.

Why does my JWT refresh token get invalidated after one use?

Your JWT refresh token gets invalidated after one use because of refresh token rotation, a security mechanism that issues a new token pair upon each refresh. This prevents replay attacks by detecting token reuse and invalidating the compromised session.