What problem does it solve?
It prevents authentication mistakes in Next.js apps by showing the correct Clerk patterns for server, client, middleware, API routes, server actions, and caching.
Core Features & Use Cases
- Server vs Client Auth (with correct awaiting): Use
await auth() in Server Components and Clerk hooks in Client Components without mixing them.
- Middleware Protection Strategies: Choose public-first or protected-first route matching and enforce access consistently across routes.
- Protected Server Actions & API Route Errors: Block unauthorized mutations and return the right HTTP codes (401 vs 403) based on auth and permissions.
- Auth-Safe Caching: Build user-scoped or org-scoped cache keys to prevent cross-user data leaks, and revalidate tags after updates.
- Token Workflows for External APIs: Generate custom JWTs via
getToken() for services like Hasura/Supabase.
Quick Start
Use the references inside clerk-nextjs-patterns to implement middleware protection for your Next.js app and ensure every protected endpoint correctly enforces Clerk authentication.