What problem does it solve?
This Skill helps developers prevent authentication mistakes in Next.js apps by showing how to correctly protect pages, APIs, and Server Actions while avoiding common security and data-leak pitfalls.
Core Features & Use Cases
- Server vs Client Auth Patterns: Use the correct Clerk auth APIs for Server Components and Client Components to eliminate undefined user/session issues.
- Route and Mutation Protection: Apply middleware and Server Action guards to ensure only authenticated and authorized users can access or change data.
- Auth-Safe Caching: Cache user/org-scoped data safely by including identifiers like userId/orgId in cache keys and revalidation tags.
- Token Handling for Integrations: Generate and pass custom JWTs (e.g., Hasura/Supabase templates) for secure server-side calls to external APIs.
- API Error Semantics: Return the correct HTTP statuses (401 vs 403) based on authentication vs permission/role checks.
Quick Start
Use clerk-nextjs-patterns to convert your page and route logic so Server Components call await auth() while API routes and Server Actions enforce authentication with correct 401/403 responses.