---
name: "clerk-react-user-management"
description: "Add drop-in authentication, user profiles, and organization switchers with Clerk."
metadata:
  author: "Clerk"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "setup clerk nextjs"
  - "protect route clerkmiddleware"
  - "clerk userbutton component"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Clerk Authentication & Drop-in User Management Components

Configures Clerk in Next.js: wrapping with <ClerkProvider>, drop-in components (<SignIn />, <SignUp />, <UserButton />, <OrganizationSwitcher />), protecting routes with clerkMiddleware, and webhook synchronization.

## When to Invoke
Invoke this skill whenever you need to:
- setup clerk nextjs
- protect route clerkmiddleware
- clerk userbutton component

## Execution SOP & Rules
1. Wrap layout: <ClerkProvider><html ...><body>{children}</body></html></ClerkProvider>.
2. Protect routes in middleware.ts using clerkMiddleware((auth, req) => { if (isProtectedRoute(req)) auth().protect(); }).
3. Add user avatar menu: <UserButton afterSignOutUrl='/' />.
4. Access current user in Server Components: const { userId } = await auth(); if (!userId) redirect('/sign-in').

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
