Loading...
Loading...
Advanced Next.js patterns - middleware, Server Actions, caching with Clerk.
npx skill4agent add clerk/skills clerk-nextjs-patternssetup/| Reference | Impact |
|---|---|
| CRITICAL - |
| HIGH - Public-first vs protected-first |
| HIGH - Protect mutations |
| HIGH - 401 vs 403 |
| MEDIUM - User-scoped caching |
await auth()@clerk/nextjs/serveruseAuth()@clerk/nextjs// Server Component
import { auth } from '@clerk/nextjs/server'
export default async function Page() {
const { userId } = await auth() // MUST await!
if (!userId) return <p>Not signed in</p>
return <p>Hello {userId}</p>
}| Symptom | Cause | Fix |
|---|---|---|
| Missing | |
| Auth not working on API routes | Missing matcher | Add `'/(api |
| Cache returns wrong user's data | Missing userId in key | Include |
| Mutations bypass auth | Unprotected Server Action | Check |
| Wrong HTTP error code | Confused 401/403 | 401 = not signed in, 403 = no permission |
setup/managing-orgs/