Clerk Auth

Enforce Clerk route protection and webhook-driven user syncing in Next.js.

1|Updated May 2, 2026
One-click install
npx skills add https://github.com/Levironexe/architect --skill clerk-auth-levironexe
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Clerk Auth
Source: https://github.com/Levironexe/architect/tree/main/skills/patterns/clerk-auth
Command: npx skills add https://github.com/Levironexe/architect --skill clerk-auth-levironexe

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill fixes authentication and authorization mistakes in Clerk-powered apps that cause broken access control, runtime hook errors, or unsafe webhook-driven user state changes.

Core Features & Use Cases

  • Route protection in Next.js middleware: Uses clerkMiddleware() with clear public route matchers so protected routes are enforced consistently before any page code runs.
  • Correct server vs client user access patterns: Uses auth() and currentUser() in Server Components/API routes, and useUser()/useAuth()/useClerk() only for UI display in Client Components.
  • Secure webhook-to-database sync for user lifecycle events: Verifies Svix signatures before updating your database, syncing user.created/updated/deleted events into a clerkId-backed users table for reliable identity mapping.
  • Organization-based multi-tenancy: Ensures every database query is scoped by orgId from auth(), preventing cross-tenant data leaks when users switch organizations.

Quick Start

Configure Clerk middleware and the webhook handler, then ask your coding agent to implement the full Clerk auth + org-scoped database flow for your app with the required files and rules.

Frequently Asked Questions about Clerk Auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I protect routes with Clerk middleware in Next.js?

Protect routes with Clerk middleware by configuring clerkMiddleware() with explicit public route matchers, ensuring protected routes are consistently enforced before any page code runs.

Why does useUser cause errors in Next.js Server Components with Clerk?

The useUser hook causes errors in Server Components because Clerk restricts useUser, useAuth, and useClerk to Client Components for UI display only, requiring auth() or currentUser() for server-side access instead.

How do I verify Clerk webhooks with Svix signatures for database sync?

Verify Clerk webhooks by validating Svix signatures before updating your database, syncing user.created, updated, and deleted events into a clerkId-backed users table for reliable identity mapping.

How do I scope database queries by organization ID in a Clerk multi-tenant app?

Scope database queries by extracting orgId from auth() in Clerk, ensuring every database query is scoped by organization ID to prevent cross-tenant data leaks when users switch organizations.

What is the correct pattern for accessing user data in Next.js API routes using Clerk?

The correct pattern for accessing user data in Next.js API routes is using auth() and currentUser() on the server, while restricting useUser and useAuth hooks to Client Components for display UI only.