clerk-core-workflow-b

Featured

Implement session management and middleware with Clerk. Use when managing user sessions, configuring route protection, or implementing token refresh and custom JWT templates. Trigger with phrases like "clerk session", "clerk middleware", "clerk route protection", "clerk token", "clerk JWT".

AI & Automation 2,266 stars 315 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Clerk Core Workflow B: Session & Middleware ## Overview Implement session management and route protection with Clerk middleware. Covers `clerkMiddleware()` configuration, `auth()` patterns, custom session claims, JWT templates for external services, organization-scoped sessions, and session token v2. ## Prerequisites - `@clerk/nextjs` installed with ClerkProvider wrapping the app - Next.js 14+ with App Router - Sign-in/sign-up flows working (`clerk-core-workflow-a` completed) ## Instructions ### Step 1: Configure clerkMiddleware with Route Matchers ```typescript // middleware.ts (project root) import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server' const isPublicRoute = createRouteMatcher([ '/', '/sign-in(.*)', '/sign-up(.*)', '/api/webhooks(.*)', '/pricing', '/blog(.*)', ]) const isAdminRoute = createRouteMatcher(['/admin(.*)']) const isApiRoute = createRouteMatcher(['/api(.*)']) export default clerkMiddleware(async (auth, req) => { // Public routes: no auth required if (isPublicRoute(req)) return // Admin routes: require org:admin role if (isAdminRoute(req)) { await auth.protect({ role: 'org:admin' }) return } // All other routes: require authentication await auth.protect() }) export const config = { matcher: [ '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', '/(api|trpc)(.*)', ], } ``` **Key behavior:** `clerkMiddleware()` does...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
7 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category