jwt-authentication

Implements JWT-based authentication with access tokens, refresh tokens, and role-based access control in Node.js.

Updated Jul 9, 2026
One-click install
npx skills add https://github.com/octanutri-clin/octaclin --skill jwt-authentication-octanutri-clin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: jwt-authentication
Source: https://github.com/octanutri-clin/octaclin/tree/main/.agents/skills/jwt-authentication
Command: npx skills add https://github.com/octanutri-clin/octaclin --skill jwt-authentication-octanutri-clin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jsonwebtoken, bcryptjs, and includes references (resource) and assets (resource) components.

What problem does it solve? Building secure authentication from scratch is error-prone: weak password hashing, missing token expiry, and unprotected routes are common vulnerabilities. This Skill provides working patterns for implementing JWT authentication in Node.js applications, covering registration, login, token verification middleware, and role-based authorization. ## Core Features & Use Cases - Token Generation & Verification: Create short-lived access tokens and long-lived refresh tokens using jsonwebtoken, with middleware that validates Bearer tokens on protected routes. - Password Security: Hash and verify passwords with bcrypt, plus a complete password reset flow using short-expiry signed tokens. - Role-Based Access Control: Restrict endpoints by user role with a reusable authorize middleware. - Use Case: You are building a REST API and need stateless authentication. Use this Skill to scaffold registration, login, token refresh, and admin-only routes without designing the security flow from zero. ## Quick Start Ask the AI to implement JWT authentication with registration, login, and a protected profile route in your Node.js Express app.

Frequently Asked Questions about jwt-authentication

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

FAQPage Schema
How do I implement JWT authentication in Node.js?

Install jsonwebtoken and bcryptjs, then create three pieces: a register endpoint that hashes passwords with bcrypt, a login endpoint that signs a JWT with jwt.sign, and middleware that verifies the Bearer token with jwt.verify before allowing access to protected routes.

How to add refresh tokens to a JWT auth flow?

Issue a second token signed with a separate refresh secret and a longer expiry such as 7 days. Store refresh tokens in your database, and on refresh requests verify the token signature and confirm it exists in storage before issuing a new access token.

What expiry times should JWT access and refresh tokens use?

Access tokens should be short-lived, typically 15 minutes to 1 hour, to limit damage from token theft. Refresh tokens can last 7 to 30 days and should be stored server-side so they can be revoked when needed.

How do I restrict routes by user role with JWT?

Include the user role in your database record, then write an authorize middleware that runs after authentication and checks whether req.user.role is in the allowed roles list. Return 403 when the role is insufficient.

Why does JWT verification fail with invalid token errors?

Verification fails when the secret does not match the one used at signing, the token has expired, or the Authorization header is malformed. Confirm the header uses the Bearer scheme and that process.env.JWT_SECRET is loaded correctly.

When should I not use JWT for authentication?

Avoid JWT when you need instant server-side session revocation without extra infrastructure, since stateless tokens remain valid until expiry. Traditional server-side sessions fit better for simple monolithic apps with strict logout requirements.