clerk-nextjs-patterns
Skill by clerk
Advanced Next.js patterns for using Clerk auth with middleware, Server Actions and caching. Aimed at developers building Next.js apps with the Clerk Next.js SDK, covering route protection, API route auth and user-scoped caching.
Install clerk-nextjs-patterns
Built from the published package, never by AI.
git clone --depth 1 https://github.com/clerk/skills /tmp/skills && mkdir -p ~/.claude/skills && cp -r /tmp/skills/skills/clerk-nextjs-patterns ~/.claude/skills/clerk-nextjs-patternsRun in your terminal. Claude Code loads skills from ~/.claude/skills automatically.
git clone --depth 1 https://github.com/clerk/skills /tmp/skills && mkdir -p ~/.gemini/antigravity-cli/skills && cp -r /tmp/skills/skills/clerk-nextjs-patterns ~/.gemini/antigravity-cli/skills/clerk-nextjs-patternsAntigravity CLI loads skills from ~/.gemini/antigravity-cli/skills, or .agents/skills for one project.
Step-by-step: install clerk-nextjs-patterns in Antigravity CLI
Skills can run scripts on your machine. Some need an API key: check the README.
About
This agent skill gives guidance on advanced Next.js patterns that use Clerk for authentication. It explains when to use await auth() in Server Components versus the useAuth hook in Client Components. It also covers protecting pages, Route Handlers and Server Actions, returning 401 versus 403 in API routes, and caching data per user with 'use cache'. A section on Cache Components explains how to fix next build errors by wrapping auth-dependent UI in Suspense.
The skill is meant for developers building with the Clerk Next.js SDK. It also covers conditional rendering with the Show component for sign-in state, roles, permissions, features and plans. It includes getToken for calling external APIs with JWT templates, and manual JWT verification for standalone API servers. It refers to a separate clerk-setup skill for basic setup.
Written from the project's SKILL.md and checked against it.
What it can do
- Server vs client authExplains await auth() on the server versus the useAuth hook on the client.
- Route protectionCalls auth.protect() in each page, Route Handler and Server Function, keeping clerkMiddleware() bare.
- Server Action protectionShows how to check auth at the start of Server Actions to protect mutations.
- API route authExplains when to return 401 for not signed in and 403 for missing permission.
- User-scoped cachingCovers caching auth data per user with 'use cache' and passing userId as an argument.
- Cache Components fixesShows where to place Suspense boundaries to fix next build prerendering errors.
- Show componentRenders content based on sign-in state, role, permission, feature or plan.
- getToken for external APIsGets a JWT from a Clerk JWT template to call third-party services.
- Manual JWT verificationVerifies Clerk session tokens on standalone API servers with verifyToken or jsonwebtoken.
What you need
- NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
- CLERK_SECRET_KEY
- CLERK_JWT_KEY or CLERK_PEM_PUBLIC_KEY for manual JWT verification
Try asking
- Show me how to protect a Server Action so only signed-in users can run it.
- Fix my next build error about uncached runtime data with Clerk auth.
- Show how to call an external GraphQL API with a Clerk JWT template.
Good to know
- createRouteMatcher is deprecated in @clerk/nextjs 7 and should not be added to new code.
- Some Show features such as feature and plan checks require Core 3.
- isAuthenticated and sessionStatus are not available in Core 2.
- Never call auth() inside 'use cache'.
Security check
ANo download-and-run commands, hidden instructions or signs of sending keys out were found.
Checked automatically: skills/clerk-nextjs-patterns/SKILL.md. This looks for known risky patterns and is not a full audit. How grades work
Inside the skill
Allowed tools: WebFetch
Alternatives to clerk-nextjs-patterns
All alternatives →Runs a 7-stage workflow for auditing, cleaning up and reviewing GitHub repositories, plus competitor analysis. Written for developers who want a repo checked for secrets, junk files and documentation gaps.
Teaches an AI assistant to build, debug and explain Gradio web UIs and ML demos in Python. It covers the core API, components, event listeners, layouts and the MCP server option. Aimed at Python developers who work with Gradio.
Recommends menus, buttons, toolbars and disclosure controls for Apple platforms using Human Interface Guidelines conventions. Built for developers and designers making iOS, iPadOS, macOS or visionOS interfaces. Checks existing project design context before asking questions.
Creates production-ready FastAPI project structures with async patterns, dependency injection, and error handling. It is for developers starting new FastAPI applications or backend API projects.
Analyzes Android apps to find user workflows to expose as AppFunctions, so AI agents and system shortcuts can run them without opening the app UI. Generates Kotlin code and refines KDoc for Android developers.
Creates, edits, validates and runs Agent QA tests, suites and hooks through MCP or CLI. It keeps canonical IDs and schema contracts intact, for developers and QA teams using Agent QA.
Compare with openclaw-github-repo-commander, gradio or hig-components-menus
clerk-nextjs-patterns: common questions
Does this skill work with the Clerk Next.js SDK?
Yes. It is written for the Clerk Next.js SDK and says to check package.json for the SDK version. Core 2 differences are noted inline.
How do I fix the next build error about uncached or runtime data?
The skill says to wrap auth-dependent Server Components and Show blocks in Suspense, and to use next build --debug-prerender to list every failing route.
Does this skill cover basic Clerk setup?
No. The source says basic setup is covered by the separate clerk-setup skill.
How do I install clerk-nextjs-patterns?
Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.
Is clerk-nextjs-patterns free?
The code is public, but no licence file was found, so check the repository before commercial use.
Is clerk-nextjs-patterns safe to use?
It scores 71 of 100. Grades: maintenance A, licence F, quality B. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.
What are alternatives to clerk-nextjs-patterns?
Similar skills: openclaw-github-repo-commander, gradio, hig-components-menus, fastapi-templates.
