auth-implementation-patterns

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

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill auth-implementation-patterns-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth-implementation-patterns
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/auth-implementation-patterns
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill auth-implementation-patterns-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building secure authentication and authorization from scratch is error-prone, and mistakes lead to token leaks, brute-force attacks, and broken access control. This Skill provides production-tested patterns for JWT, sessions, OAuth2, and RBAC so you implement auth correctly the first time. ## Core Features & Use Cases - JWT & Refresh Token Flows: Generate short-lived access tokens with hashed, revocable refresh tokens stored in a database. - Session & OAuth2 Login: Configure Redis-backed Express sessions and Passport.js strategies for Google and GitHub social login. - Authorization Middleware: Apply role hierarchies, permission-based checks, and resource ownership validation to protect routes. - Use Case: When adding login to an Express API, use this Skill to scaffold registration with bcrypt password hashing, rate-limited login endpoints, and RBAC middleware protecting admin routes. ## Quick Start Implement JWT authentication with refresh token rotation and role-based access control for my 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?

Issue a long-lived refresh token alongside the access token, hash it, and store it in a database with an expiration date. On refresh, verify the token signature and database record before issuing a new access token, and delete stored tokens on logout.

Should I use sessions or JWT for API authentication?

Sessions store state server-side in Redis and suit traditional web apps with cookie-based auth, while JWTs are stateless and scale horizontally for distributed APIs. The Skill covers both patterns with Express middleware examples.

How do I add Google OAuth login with Passport.js?

Configure the GoogleStrategy with your client ID, secret, and callback URL, then find or create a user from the OAuth profile in the verify callback. After successful authentication, generate your own JWT and redirect to the frontend with the token.

Why is storing JWTs in localStorage insecure?

Tokens in localStorage are accessible to any JavaScript running on the page, making them vulnerable to XSS theft. Use httpOnly, secure, sameSite cookies instead so browsers never expose the token to client-side scripts.

How do I restrict routes to admins in Express?

Use role-based middleware that checks the authenticated user's role against a hierarchy before calling next(). Combine it with permission-based checks or resource ownership validation for finer-grained control over who can modify specific records.