auth-implementation-patterns

Implements JWT authentication, token rotation, MFA, and multi-tenant authorization patterns for NestJS backends.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Designing secure authentication and authorization flows is error-prone: missing refresh token rotation, weak tenant isolation, client-only MFA, and missing audit trails are common vulnerabilities. This Skill grounds identity flows in the project's approved baseline so implementations follow consistent, reviewed security patterns. ## Core Features & Use Cases - JWT with Token Rotation: Enforces short-lived access tokens, refresh token rotation, reuse detection, and revocation on password changes or security events. - Multi-Tenant Authorization: Requires explicit tenant resolution on every authenticated request, with RBAC or ABAC policies separated from authentication. - MFA and Audit Guidance: Covers TOTP enrollment, secret handling, and audit logging for sensitive operations like credential or permission changes. - Use Case: When building a login endpoint with refresh tokens in a NestJS multi-tenant app, activate this Skill to get the checklist, anti-patterns, and code patterns for rotation, tenant scoping, and revocation. ## Quick Start Ask the AI to design a login and refresh token flow with MFA and tenant isolation for the NestJS backend using this Skill.

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 refresh token rotation in NestJS?

Issue a short-lived access token (around 15 minutes) alongside a long-lived refresh token stored hashed in the database. On each refresh, rotate the refresh token, and invalidate it on reuse detection, revocation, password change, or account lockout.

What is the difference between RBAC and ABAC for authorization?

RBAC assigns permissions through stable roles, while ABAC evaluates attributes of the tenant, resource, or request context. Use RBAC for simple role-based rules and ABAC when the domain requires contextual checks like tenant or resource ownership.

How do I enforce multi-tenant isolation in authenticated requests?

Resolve the tenant explicitly on every authenticated request and propagate it through internal layers. Never hardcode tenants or derive them insecurely, and validate permissions against both the resource and the tenant context.

Should MFA be implemented on the client or server?

MFA must be verified server-side using TOTP or an approved mechanism, with secrets stored outside versioned code. Client-only MFA is an anti-pattern because it can be bypassed and provides no real security.

Why should login error messages not reveal whether an account exists?

Generic error messages prevent account enumeration attacks where attackers probe which emails are registered. Only reveal account state when the business case explicitly requires it and it has been approved.