clerk-react-patterns

Implement Clerk authentication patterns for React SPAs built with Vite or Create React App.

Updated Sep 19, 2026
One-click install
npx skills add https://github.com/paramcodes/autobro --skill clerk-react-patterns-paramcodes
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: clerk-react-patterns
Source: https://github.com/paramcodes/autobro/tree/main/.agents/skills/clerk-react-patterns
Command: npx skills add https://github.com/paramcodes/autobro --skill clerk-react-patterns-paramcodes

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @clerk/react, and includes references (resource) components.

What problem does it solve? Adding authentication to a React single-page application requires wiring up providers, guarding routes, handling loading states, and managing session tokens, and small mistakes like missing the isLoaded guard or using the wrong environment variable prefix cause subtle bugs. ## Core Features & Use Cases - ClerkProvider Setup: Configure @clerk/react in a Vite or CRA app with the correct VITE_CLERK_PUBLISHABLE_KEY environment variable. - Auth Hooks: Use useAuth, useUser, and useClerk with proper isLoaded guards to read sign-in state, user profiles, and session tokens. - Protected Routes & Custom Flows: Build React Router v6/v7 protected routes and custom sign-in/sign-up forms with useSignIn and useSignUp. - Use Case: You have a React SPA with React Router and need /dashboard and /settings accessible only to signed-in users, with everyone else redirected to /sign-in. ## Quick Start Set up Clerk authentication in my Vite React app with ClerkProvider, a protected dashboard route, and a custom sign-in form.

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 Clerk authentication in a Vite React app?▼

Install @clerk/react, add VITE_CLERK_PUBLISHABLE_KEY to your .env file, and wrap your App in ClerkProvider inside main.tsx. Read the key via import.meta.env.VITE_CLERK_PUBLISHABLE_KEY and pass it as the publishableKey prop.

How to protect React Router routes with Clerk?▼

Create a ProtectedRoute component that calls useAuth, returns a loading state while isLoaded is false, and renders <Navigate to="/sign-in" replace /> when the user is not signed in. Wrap protected routes with this component using the Outlet pattern in React Router v6/v7.

How do I build a custom sign-in form with Clerk React hooks?▼

Use the useSignIn hook, call signIn.create with the email identifier and password, then check result.status === 'complete' before calling setActive with the createdSessionId. Catch errors and display the first error message from the Clerk error response.

Why is isSignedIn undefined in my Clerk React app?▼

isSignedIn is undefined while Clerk is still initializing, meaning isLoaded is false. Always check isLoaded first and render a loading state before trusting any auth values from useAuth or useUser.

How do I get a Clerk session token for API calls in React?▼

Call getToken() from the useAuth hook and await the result, since it returns a Promise. Null-check the token, then attach it as a Bearer token in the Authorization header of your fetch request.

Can I use @clerk/react with Next.js?▼

No, @clerk/react is client-only and intended for Vite or CRA single-page applications. For Next.js use @clerk/nextjs instead, which provides server-side auth() support that the React SPA SDK does not have.