clerk-react-router-patterns

Automate Clerk authentication patterns in React Router v7 apps.

1|1|Updated May 1, 2026
One-click install
npx skills add https://github.com/pyqdeck/pyqdeck-core --skill clerk-react-router-patterns-pyqdeck
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clerk-react-router-patterns
Source: https://github.com/pyqdeck/pyqdeck-core/tree/main/.agents/skills/clerk-react-router-patterns
Command: npx skills add https://github.com/pyqdeck/pyqdeck-core --skill clerk-react-router-patterns-pyqdeck

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides robust Clerk-based authentication patterns for React Router v7 apps, including rootAuthLoader, getAuth in loaders/actions, clerkMiddleware, SSR data access, and org switching to securely manage user context across navigation and server rendering.

Core Features & Use Cases

  • rootAuthLoader integration to pass Clerk state to the client and hydrate user data on initial load.
  • getAuth in loaders and actions to gate protected routes and drive data-fetching logic based on authentication status.
  • clerkMiddleware for server-side authentication attachment and consistent request context.
  • SSR data access via clerkClient to fetch user/org details on the server for initial render.
  • Org switching patterns to maintain correct org context during navigation and data fetching.

Quick Start

Set up Clerk with React Router by wiring rootAuthLoader in root.tsx and protecting routes with getAuth in loaders and actions.

Frequently Asked Questions about clerk-react-router-patterns

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

FAQPage Schema
How do I set up Clerk authentication in React Router v7?

Set up Clerk authentication in React Router v7 by wiring rootAuthLoader in your root route and protecting child routes with getAuth in loaders and actions. This pattern securely gates protected routes and hydrates user data on initial load.

What is rootAuthLoader used for in Clerk and React Router?

rootAuthLoader in Clerk and React Router passes Clerk authentication state to the client and hydrates user data on initial load. It ensures user context is preserved across navigation and server rendering for dashboards and protected routes.

How does Clerk middleware handle authentication during SSR data fetching?

Clerk middleware handles authentication during SSR data fetching by attaching server-side authentication context to requests. This provides consistent request context for loaders and actions to drive data-fetching logic based on authentication status.

Can I use Clerk to manage org switching in a React Router dashboard?

Yes, you can use Clerk to manage org switching in a React Router dashboard by applying org switching patterns. These patterns maintain correct organization context during navigation and data fetching to properly scope org data.

How do I access user and organization details on the server for initial render?

Access user and organization details on the server for initial render by using clerkClient for SSR data access. This fetches user and org details directly on the server, securely managing user context during server rendering.