This covers the essential Clerk patterns you need for Next.js App Router projects: setting up ClerkProvider, protecting routes with middleware, and accessing auth state in server components. The middleware guidance is solid, emphasizing a single root file and createRouteMatcher for route groups. There's a sharp edges table that lists eight issues from critical to medium severity, though the actual problems aren't described in what I'm seeing. If you're adding Clerk to a Next.js 14 or 15 app, this gives you the core implementation patterns for sign in, sign up, route protection, and user session handling without hunting through docs.

skills.sh installs
220
GitHub stars
33.2K
last updated
Aug 21, 2026

Install

$ npx -y skills add davila7/claude-code-templates --skill clerk-auth --agent claude-code

Installs into .claude/skills of the current project.

Files

Clerk Authentication

Patterns

Next.js App Router Setup

Complete Clerk setup for Next.js 14/15 App Router.

Includes ClerkProvider, environment variables, and basic sign-in/sign-up components.

Key components:

  • ClerkProvider: Wraps app for auth context
  • , : Pre-built auth forms
  • : User menu with session management

Middleware Route Protection

Protect routes using clerkMiddleware and createRouteMatcher.

Best practices:

  • Single middleware.ts file at project root
  • Use createRouteMatcher for route groups
  • auth.protect() for explicit protection
  • Centralize all auth logic in middleware

Server Component Authentication

Access auth state in Server Components using auth() and currentUser().

Key functions:

  • auth(): Returns userId, sessionId, orgId, claims
  • currentUser(): Returns full User object
  • Both require clerkMiddleware to be configured

⚠️ Sharp Edges

Sponsors

Details

Repository
github.com/davila7/claude-code-templates
Categories
Backend & APIs, Security
First seen
Jun 3, 2026

More from davila7/claude-code-templates

All 618
1martinholovsky avatargraphql-expertmartinholovsky/claude-skills-generatorExpert GraphQL developer specializing in type-safe API development, schema design, resolver optimization, and federation architecture. Use when building GraphQL218skills.sh installs
2yonatangross avatarapi-designyonatangross/orchestkitAPI contract design for REST and GraphQL, covering resource shape, URL and header versioning with deprecation windows, RFC 9457 Problem Details error handling, 211skills.sh installs
3davepoon avatarauth-patternsdavepoon/buildwithclaudeThis skill should be used when the user asks about "authentication in Next.js", "NextAuth", "Auth.js", "middleware auth", "protected routes", "session managemen182skills.sh installs
4borghei avatardatabase-designerborghei/claude-skillsDatabase design with schema analysis, index optimization, and migration generation for PostgreSQL, MySQL, MongoDB, and DynamoDB. Use when designing schemas, opt170skills.sh installs
5davila7 avatarfastmcp-serverdavila7/claude-code-templatesComplete guide for building MCP servers with FastMCP 3.0 - tools, resources, authentication, providers, middleware, and deployment. Use when creating Python MCP154skills.sh installs
6webmaxru avatarenonic-api-referencewebmaxru/enonic-agent-skillsEnonic XP server-side JavaScript/TypeScript API reference for all /lib/xp/* libraries. Provides function signatures, parameters, return types, and usage example141skills.sh installs