Auth Patterns Skill
Core Principles
- Prevent user enumeration: Login errors must be identical for "user not found" and "wrong password".
- Constant-time comparison: Always use
crypto.timingSafeEqualfor token comparison. - Short-lived access tokens: 15 minutes max; refresh tokens rotate on use.
- RBAC at middleware level: Authorization check before business logic, not inside it.
- Never trust the client: Re-verify permissions on every request, not just at login.
References
references/jwt-implementation.md— Access/refresh tokens, rotation, httpOnly cookies, revocationreferences/oauth-oidc.md— Authorization code + PKCE, token exchange, provider integrationreferences/session-implementation.md— Redis sessions, session fixation, CSRF protectionreferences/multi-tenant-auth.md— Tenant context middleware, RLS, RBAC permission matrixreferences/tenant-data-isolation.md— Schema-per-tenant, database-per-tenant, hybrid tier routing, ABAC, org-level permissions