What problem does it solve?
This guide reduces security and reliability issues caused by inconsistent use of authentication and authorization mechanisms across the codebase, commonly known as auth drift. It helps developers choose the correct layer to avoid privilege escalation, data leaks, and broken access controls when adding or changing endpoints and middleware.
Core Features & Use Cases
- Layered decision tree: Clear guidance on when to use Supabase sessions for middleware, APISecurityChecker for API routes, RBAC for fine-grained permissions, and owner bypass for platform-level operations.
- Implementation map: References to where each pattern is implemented (middleware.ts, lib/auth/*, lib/security/api-security-checker.ts) and common migration paths for legacy routes.
- Security patterns: PKCE for OAuth exchanges, fail-secure RBAC behavior, rate limiting, and required environment variables for safe operation.
- Use Case: Migrate legacy API routes that call raw JWT verification to APISecurityChecker, ensuring consistent rate limiting and CSRF protections.
Quick Start
Audit the /api/posts route to replace raw jwt.verify usage with APISecurityChecker and produce a step-by-step migration plan.