clerk-react-patterns

Implement Clerk authentication patterns for React SPAs with protected routes.

Updated Apr 7, 2026
One-click install
npx skills add https://github.com/koushik-hait/xigenis-landingpage-v1 --skill clerk-react-patterns-koushik-hait
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clerk-react-patterns
Source: https://github.com/koushik-hait/xigenis-landingpage-v1/tree/main/.agents/skills/clerk-react-patterns
Command: npx skills add https://github.com/koushik-hait/xigenis-landingpage-v1 --skill clerk-react-patterns-koushik-hait

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you implement reliable authentication in a React SPA by showing the correct setup for ClerkProvider, protected routes, and custom sign-in flows without breaking React Router navigation.

Core Features & Use Cases

  • ClerkProvider setup for Vite/CRA: Initialize @clerk/react at the app root using the publishable key from VITE_CLERK_PUBLISHABLE_KEY.
  • Auth state guards with hooks: Use useAuth/useUser/useClerk patterns, including the required isLoaded guard before trusting isSignedIn.
  • Protected routes in React Router v6/v7: Redirect unauthenticated users to /sign-in and render protected pages via <Outlet />.
  • Custom sign-in and sign-up flows: Use useSignIn and useSignUp to authenticate with email/password and handle multi-step statuses like complete and missing_requirements.
  • Backend API authorization: Retrieve session tokens with getToken and send them as a Bearer token for authenticated API calls.

Quick Start

Set up ClerkProvider in src/main.tsx using VITE_CLERK_PUBLISHABLE_KEY and add a ProtectedRoute wrapper that redirects to /sign-in unless isLoaded is true and isSignedIn is true.

Frequently Asked Questions about clerk-react-patterns

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

FAQPage Schema
How do I set up protected routes in a React SPA using Clerk and React Router?

To set up protected routes in a React SPA with Clerk, wrap your routes in a ProtectedRoute component that redirects unauthenticated users. Use the useAuth hook, ensuring the isLoaded state is true before trusting isSignedIn, and render pages via the <Outlet /> component.

Why does my Clerk auth state show unauthenticated before the page fully loads?

Clerk auth state shows unauthenticated before loading completes because hook-derived state requires initialization. You must implement an isLoaded guard before trusting the isSignedIn value from the useAuth or useUser hooks to prevent redirecting authenticated users prematurely.

Can I build custom sign-in and sign-up flows with Clerk hooks in React?

Yes, you can build custom sign-in and sign-up flows in React using the useSignIn and useSignUp hooks. These hooks allow you to authenticate users with email and password while handling multi-step status requirements like complete and missing_requirements.

How do I send authenticated API requests with a Clerk session token?

To send authenticated API requests with a Clerk session token, use the getToken function to retrieve the active session token. Send this token in the Authorization header as a Bearer token to authorize your backend API calls for the authenticated user.

Where do I place the ClerkProvider when initializing a Vite or Create React App project?

Place the ClerkProvider at the app root, typically in src/main.tsx for Vite or Create React App projects. Initialize it using the VITE_CLERK_PUBLISHABLE_KEY environment variable to ensure authentication context is available across your entire React SPA.