clerk-nextjs-patterns
Advanced Next.js patterns for authentication, middleware, Server Actions, and user-scoped caching with Clerk.
- Distinguishes server-side
await auth()from client-sideuseAuth()hook; mixing them is a common breaking mistake - Covers middleware strategies (public-first vs protected-first), API route protection, and proper HTTP status codes (401 vs 403)
- Includes user-scoped caching patterns with
unstable_cacheand protecting Server Actions from unauthorized mutations - Provides Core 2 compatibility notes throughout; check
package.jsonfor SDK version and follow version-specific guidance onisAuthenticated,sessionStatus, and component APIs
Next.js Patterns
Version: Check
package.jsonfor the SDK version — seeclerkskill for the version table. Core 2 differences are noted inline with> **Core 2 ONLY (skip if current SDK):**callouts.
For basic setup, see clerk-setup skill.
What Do You Need?
| Task | Reference |
|---|---|
Server vs client auth (auth() vs hooks) |
references/server-vs-client.md |
| Configure middleware (public-first vs protected-first) | references/middleware-strategies.md |
| Protect Server Actions | references/server-actions.md |
| API route auth (401 vs 403) | references/api-routes.md |
| Cache auth data (user-scoped caching) | references/caching-auth.md |
References
| Reference | Description |
More from clerk/skills
clerk
Clerk authentication router. Use when user asks about adding authentication,
7.7Kclerk-setup
Add Clerk authentication to any project by following the official quickstart
6.9Kclerk-custom-ui
Custom authentication flows and component appearance - hooks (useSignIn,
6.7Kclerk-webhooks
Clerk webhooks for real-time events and data syncing. Verify with verifyWebhook
6.1Kclerk-testing
E2E testing for Clerk apps. Use with Playwright or Cypress for auth flow
5.8Kclerk-orgs
Clerk Organizations for B2B SaaS - create multi-tenant apps with org
5.3K