auth-implementation-patterns

Implements JWT, OAuth2, session, and RBAC authentication patterns for APIs.

Updated Jul 28, 2026
One-click install
npx skills add https://github.com/truongnat/Restly --skill auth-implementation-patterns-truongnat
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: auth-implementation-patterns
Source: https://github.com/truongnat/Restly/tree/main/.agents/skills/auth-implementation-patterns
Command: npx skills add https://github.com/truongnat/Restly --skill auth-implementation-patterns-truongnat

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building secure authentication and authorization is error-prone, and mistakes like weak password hashing, missing token expiration, or client-side-only checks create serious vulnerabilities. This Skill provides proven implementation patterns for JWT, sessions, OAuth2, and RBAC so you can build access control correctly the first time. ## Core Features & Use Cases - JWT & Refresh Token Flows: Generate short-lived access tokens, store hashed refresh tokens, and handle revocation for logout across devices. - Session & OAuth2 Authentication: Configure Redis-backed Express sessions with secure cookies and integrate Google/GitHub social login via Passport.js. - Authorization Patterns: Implement role hierarchies, permission-based access control, and resource ownership checks as Express middleware. - Use Case: When adding login to a REST API, use this Skill to scaffold registration with bcrypt password hashing, rate-limited login endpoints, and middleware that protects routes by role. ## Quick Start Ask the AI to implement JWT authentication with refresh tokens and role-based route protection for your Express API.

Frequently Asked Questions about auth-implementation-patterns

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

FAQPage Schema
How do I implement JWT authentication in Express?▼

Sign a short-lived access token with jsonwebtoken containing userId, email, and role claims, then verify it in middleware that reads the Bearer token from the Authorization header. Attach the decoded payload to the request object for downstream route handlers.

How does refresh token rotation work with JWT?▼

Store a hashed refresh token in the database with an expiration date, then verify it on refresh requests before issuing a new access token. Revoke tokens by deleting them on logout, or delete all user tokens to log out every device.

Should I use sessions or JWT for API authentication?▼

Sessions store state server-side (e.g., in Redis) and suit traditional apps with cookie-based clients, while JWT is stateless and scales horizontally across services. OAuth2 via Passport.js is the right choice when delegating login to Google or GitHub.

How do I implement role-based access control middleware?▼

Define a role hierarchy mapping each role to the roles it inherits, then write middleware that checks the authenticated user's role against required roles and returns 403 when permissions are insufficient. Permission-based checks and resource ownership validation extend this for finer control.

Why is storing JWT in localStorage insecure?▼

localStorage is accessible to any JavaScript on the page, so an XSS vulnerability lets attackers steal tokens. Use httpOnly, secure, sameSite cookies instead so tokens are never exposed to client-side scripts.

How do I rate limit login endpoints to prevent brute force attacks?▼

Use express-rate-limit with a Redis store to cap login attempts, for example 5 tries per 15 minutes per client. Apply a separate, higher limit to general API routes so normal traffic is unaffected.