Content
Clerk Auth Patterns
Production authentication patterns for web applications using Clerk as the primary provider, with Auth0 and generic OAuth 2.0 as alternatives. Covers JWT verification, session management, RBAC, Supabase row-level security integration, multi-tenant access control, and middleware-driven auth enforcement.
When to use
- Adding authentication to a Next.js application
- Implementing role-based access control (RBAC) for API routes
- Integrating Clerk with Supabase for row-level security
- Building multi-tenant applications with organization-scoped access
- Setting up OAuth 2.0 flows with third-party providers
- Protecting API routes with server-side auth checks
When NOT to use
- Machine-to-machine auth without user context — use API keys or mTLS instead
- Embedded device authentication — use device-specific protocols
- General API hardening (use
api-securityinstead) - Threat modeling (use
security-threat-modelinstead)
Core concepts
| Concept | Description |
|---|---|
| JWT (JSON Web Token) | Signed token containing user claims, verified server-side without a session store |
| Session | Server-managed auth state, typically stored in HTTP-only cookies |
| RBAC | Role-Based Access Control — permissions derived from assigned roles |