auth-implementation-patterns

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

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill auth-implementation-patterns-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth-implementation-patterns
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/auth-implementation-patterns
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill auth-implementation-patterns-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

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 lead to serious vulnerabilities. This Skill provides production-tested patterns for implementing auth systems correctly the first time. ## Core Features & Use Cases - JWT Authentication: Generate and verify short-lived access tokens with refresh token rotation, revocation, and database-backed token storage. - Session & OAuth2 Login: Configure Redis-backed Express sessions and social login via Passport.js strategies for Google and GitHub. - Authorization Patterns: Implement role-based access control (RBAC), permission-based checks, and resource ownership validation as Express middleware. - Use Case: When adding login to a REST API, use this Skill to scaffold registration with bcrypt password hashing, JWT issuance, rate-limited login endpoints, and role-protected routes. ## Quick Start Use the auth-implementation-patterns skill to implement JWT authentication with refresh tokens 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, store a hashed copy in the database, and verify both the JWT signature and database record when refreshing. Revoke tokens by deleting the stored hash on logout or across all devices per user.

Should I use session-based or token-based authentication?

Session-based auth stores state server-side (e.g., in Redis) and suits traditional web apps with cookies. Token-based JWT auth is stateless and scales horizontally, making it better for APIs and distributed services.

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, issue your own JWT and redirect the user to the frontend with the token.

Why is storing JWTs in localStorage a security risk?

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

How do I restrict API routes by user role in Express?

Define a role hierarchy mapping roles to their inherited permissions, then create middleware that checks the authenticated user's role against required roles. Return 403 when the user's role lacks the required permission before reaching the route handler.