What problem does it solve?
This Skill documents vetted Clerk authentication patterns for Next.js to prevent common mistakes like flashing unauthenticated content, leaking cached data between users, and misconfigured middleware that leaves API routes unprotected.
Core Features & Use Cases
- Middleware Strategies: public-first and protected-first approaches, route matchers, and session task handling to control access across pages and APIs.
- Server vs Client Auth Guidance: clear rules for using await auth() and currentUser in server components versus useAuth/useUser and Show/SignedIn in client components.
- Server Actions, API Protection & JWTs: patterns for protecting server actions, returning correct 401/403 responses, using getToken for custom JWTs to call external APIs, and manual verification when not using Clerk middleware.
- Real-world example: migrate a client-side dashboard that uses hooks and useEffect redirects into a server component that uses await auth(), protect API routes with clerk middleware, and cache per-user data safely.
Quick Start
Convert a client-side dashboard to a server component by replacing client hooks with await auth() from @clerk/nextjs/server, add clerk middleware to protect dashboard routes, and include userId in your cache keys.