What problem does it solve?
Prevents common authentication mistakes and security gaps when integrating Clerk with Next.js, such as missing awaits for server auth, mixing server and client APIs, incorrect HTTP status usage, and cache keys that leak user data.
Core Features & Use Cases
- Server vs Client Auth Guidance: Clear rules for using await auth() and server imports versus client hooks to avoid undefined values and UI flashes.
- Middleware Strategies: Patterns for public-first and protected-first middleware, route matchers, and handling pending session tasks.
- Protecting Endpoints: Recipes for securing Server Actions, API routes with proper 401/403 semantics, and verifying tokens for external services.
- Caching Best Practices: User- and org-scoped cache keys and revalidation strategies to prevent cross-user data leakage.
- Use Cases: Convert client-side pages to server components, add auth to API routes, protect dashboard routes with middleware, and obtain custom JWTs for external APIs like Hasura.
Quick Start
Use the clerk-nextjs-patterns guidance to convert a client-side Next.js page that uses useAuth into a server component using await auth(), update middleware to protect /dashboard, and ensure cache keys include the userId.