What problem does it solve? Securing a Next.js application with Clerk involves many distinct patterns—middleware route protection, Server Action authorization, API route 401/403 handling, and user-scoped caching—and mixing up server and client auth APIs causes common bugs like undefined userId or data leaking between users. ## Core Features & Use Cases - Server vs Client Auth Guidance: Enforces correct usage of await auth() from @clerk/nextjs/server in Server Components versus useAuth() hooks in Client Components. - Middleware Strategies: Provides public-first and protected-first clerkMiddleware configurations with createRouteMatcher, permission-gated routes, and token-based protection for machine APIs. - Server Actions & API Routes: Shows how to protect mutations and route handlers with authentication and role/permission checks, returning correct 401 vs 403 status codes. - Session Tokens & JWTs: Covers getToken() with JWT templates for third-party APIs like Hasura and Supabase, plus manual JWT verification for standalone servers. - Use Case: When your API route at app/api/data/route.ts is publicly accessible, use this Skill to add a Clerk auth() check that returns 401 for unauthenticated requests and scopes data to the signed-in user. ## Quick Start Ask the AI to protect your Next.js dashboard routes and API endpoints with Clerk middleware and auth() checks using the clerk-nextjs-patterns skill.