auth_patterns

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

Updated Jan 14, 2026
One-click install
npx skills add https://github.com/jvsandhu/agentic-skills --skill auth-patterns-jvsandhu
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth_patterns
Source: https://github.com/jvsandhu/agentic-skills/tree/main/skills/auth_patterns
Command: npx skills add https://github.com/jvsandhu/agentic-skills --skill auth-patterns-jvsandhu

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jsonwebtoken, bcrypt, express-session, connect-redis, redis, passport, passport-google-oauth20, passport-github2, express-rate-limit, rate-limit-redis, zod, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve? Building secure authentication and authorization is error-prone, and mistakes like weak password hashing, missing rate limits, or insecure token storage lead to breaches. This Skill provides production-tested patterns for implementing auth systems correctly the first time. ## Core Features & Use Cases - JWT & Refresh Token Flows: Generate short-lived access tokens with database-backed refresh token rotation and revocation. - Session & OAuth2 Authentication: Set up Redis-backed Express sessions or social login via Passport.js with Google and GitHub strategies. - Authorization Models: Implement role-based access control, permission-based checks, and resource ownership validation middleware. - Use Case: When securing a new Express API, apply the JWT middleware, bcrypt password hashing with Zod validation, and login rate limiting to ship a hardened auth layer. ## Quick Start Implement JWT authentication with refresh tokens and role-based access control for my Express API.

Frequently Asked Questions about auth_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 the user ID and role, 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.

Should I use JWT or session-based authentication?

Use JWT for SPAs, mobile apps, and horizontally scaled services since tokens are stateless. Use server-side sessions with Redis storage for traditional server-rendered apps where simple revocation and cookie-based transport matter more.

How do I add Google OAuth2 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, issue your own JWT and redirect the user to the frontend with the token.

Where should I store JWT tokens on the client?

Avoid localStorage because it is vulnerable to XSS attacks that can steal tokens. Prefer httpOnly, secure, sameSite cookies so JavaScript cannot access the token and CSRF risk is reduced.

How do I implement role-based access control in Express?

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. Return 403 when the user's role lacks the required permission.

Why is my login endpoint vulnerable to brute force attacks?

Without rate limiting, attackers can attempt unlimited password guesses. Apply express-rate-limit with a Redis store to restrict login attempts, for example 5 tries per 15 minutes per client.