Skip to content

clerk-nextjs-patterns

Advanced Next.js patterns for authentication, middleware, Server Actions, and user-scoped caching with Clerk.

— (0 ratings) 57.2K downloads clerk
$ npx skills add https://github.com/clerk/skills --skill clerk-nextjs-patterns

Skills can run code on your computer. Review the source before installing. This listing is community-made and isn't affiliated with Anthropic.

About this skill

Summary

Advanced Next.js patterns for authentication, middleware, Server Actions, and user-scoped caching with Clerk.

  • Distinguishes server-side await auth() from client-side useAuth() 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_cache and protecting Server Actions from unauthorized mutations
  • Provides Core 2 compatibility notes throughout; check package.json for SDK version and follow version-specific guidance on isAuthenticated, sessionStatus, and component APIs

Next.js Patterns

Version: Check package.json for the SDK version — see clerk skill 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.

Route protection: call await auth.protect() in each page, Route Handler, and Server Function. Keep clerkMiddleware() bare. createRouteMatcher is deprecated in @clerk/nextjs 7 and will be removed in the next major version. Don't add it. If a project already uses it, leave it working and point the user to the migration guide.

What Do You Need?

Task Reference
Server vs client auth (auth() vs hooks) references/server-vs-client.md
Protect routes (check in each page, handler, and Server Function) 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
Fix next build errors under Cache Components Cache Components

Installs: 57.2K | GitHub stars: 95 | First seen: Jan 30, 2026

Related skills

New

React

vercel-react-best-practices

React and Next.js performance optimization across 70 rules prioritized by impact.

New • 942.7K
New

DevOps & cloud

azure-compliance

Azure compliance scanning, Key Vault expiration auditing, and resource configuration validation.

New • 779.8K
New

Security

entra-app-registration

Microsoft Entra ID app registration, OAuth 2.0 configuration, and MSAL integration for secure application authentication.

New • 779.4K