/clerk:middleware-protectionfrom clerk
Configures Clerk middleware for route protection and authorization in Next.js apps. Covers public/protected routes, role-based access, API guards, and matcher patterns.
Ships in clerk. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Comprehensive route protection and authorization patterns for Clerk middleware in Next.js applications. Provides middleware configuration, route matchers, role-based access control, and authentication boundaries.
auth() helperCreate middleware.ts in project root
clerkMiddleware from @clerk/nextjs/serverConfigure Public Routes
Set Protected Routes
Role-Based Access Control
Conditional Route Protection
API Route Protection
Multi-Tenant Protection
Test Authentication Boundaries
Test Edge Cases
Use these templates for middleware implementation:
templates/middleware.ts - Basic middleware configurationtemplates/route-matchers.ts - Route matching patternstemplates/role-based-middleware.ts - Role-based access controltemplates/public-routes-config.ts - Public route definitionstemplates/protected-routes-config.ts - Protected route setuptemplates/api-middleware-config.ts - API route protectiontemplates/organization-middleware.ts - Organization-scoped protectiontemplates/conditional-middleware.ts - Conditional route logictemplates/custom-redirects.ts - Custom redirect handlingUse these scripts for middleware setup and testing:
scripts/generate-middleware.sh - Generate middleware.ts with configurationscripts/configure-routes.sh - Setup route protection patternsscripts/test-protection.sh - Test authentication guards and boundariesscripts/validate-middleware.sh - Validate middleware configurationSee complete examples in the examples/ directory:
examples/basic-middleware.ts - Simple middleware setupexamples/public-private-routes.ts - Public vs protected routesexamples/api-middleware.ts - API route protectionexamples/role-based-protection.ts - Role-based access controlexamples/organization-routes.ts - Organization-scoped routesexamples/conditional-routing.ts - Conditional protection logicexamples/custom-auth-flow.ts - Custom authentication flowsexamples/middleware-tests.ts - Middleware unit testsexamples/integration-tests.ts - Full protection integration testsCRITICAL: When generating middleware configuration:
your_clerk_secret_key_hereprocess.env.CLERK_SECRET_KEY.env* to .gitignore (except .env.example)Next.js Version:
Clerk SDK:
Configuration Files:
.env.local with Clerk environment variablesmiddleware.ts in project root.gitignore protecting secrets// Public: /, /about, /pricing
// Protected: /dashboard/*, /profile/*
// Matcher: Protect everything except public routes
// Protect all /api/* except /api/webhooks/clerk
// Validate session tokens on protected endpoints
// Return 401 for unauthenticated requests
// Require organization membership for /org/*
// Check active organization in middleware
// Redirect to organization selection if needed
// Check user roles in middleware
// Redirect based on permissions (admin vs user)
// Implement feature-specific access control
Middleware Not Running
Infinite Redirect Loops
Protected Routes Accessible
Session Not Found
Purpose: Provide comprehensive middleware protection patterns for Clerk authentication Load when: Implementing route guards, protecting routes, setting up middleware, configuring auth boundaries
examples/api-middleware.ts (opens in a new tab)examples/basic-middleware.ts (opens in a new tab)examples/conditional-routing.ts (opens in a new tab)examples/organization-routes.ts (opens in a new tab)examples/public-private-routes.ts (opens in a new tab)examples/role-based-protection.ts (opens in a new tab)examples/validate_routes.py (opens in a new tab)scripts/configure-routes.sh (opens in a new tab)scripts/generate-middleware.sh (opens in a new tab)scripts/test-protection.sh (opens in a new tab)scripts/validate-middleware.sh (opens in a new tab)templates/middleware.ts (opens in a new tab)templates/organization-middleware.ts (opens in a new tab)templates/role-based-middleware.ts (opens in a new tab)templates/route-matchers.ts (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub vanman2024/ai-dev-marketplace --plugin clerk10 skills in this plugin
/api-authenticationBackend API authentication patterns with Clerk JWT middleware and route protection. Use when building REST APIs, GraphQL APIs, protecting backend routes, implementing JWT validation, setting up Express middleware, or when user mentions API authentication, backend security, JWT tokens, or protected endpoints./auth-componentsPre-built and custom Clerk authentication component templates with theming and customization patterns. Use when building authentication UI, creating sign-in/sign-up pages, customizing Clerk components, implementing user buttons, theming auth flows, or when user mentions Clerk components, SignIn, SignUp, UserButton, auth UI, appearance customization, or authentication theming./billing-integrationClerk Billing and Stripe subscription management setup. Use when implementing subscriptions, configuring pricing plans, setting up billing, adding payment flows, managing entitlements, or when user mentions Clerk Billing, Stripe integration, subscription management, pricing tables, payment processing, or monetization./nextjs-integrationComplete Next.js integration patterns for Clerk authentication with App Router and Pages Router. Use when setting up Clerk in Next.js, configuring authentication middleware, implementing protected routes, setting up server/client components with auth, or when user mentions Clerk Next.js setup, App Router auth, Pages Router auth, or Next.js authentication integration./oauth-providersConfigure OAuth authentication providers for Clerk (Google, GitHub, Discord, Apple, Microsoft, Facebook, LinkedIn, Twitter, and 11+ more). Use when setting up social login, configuring OAuth providers, implementing authentication flows, generating redirect URLs, testing OAuth connections, or when user mentions Clerk OAuth, social authentication, provider setup, or multi-provider auth./organization-managementImplement Clerk multi-tenant organization features with RBAC, role-based access control, organization switching, member management, and tenant isolation. Use when building multi-tenant SaaS applications, implementing organization hierarchies, configuring custom roles and permissions, setting up organization-scoped data isolation, or when user mentions organizations, RBAC, multi-tenancy, roles, permissions, organization switcher, member management, or tenant isolation.Other plugins' skills for the same job