clerk-react-patterns

Set up Clerk authentication in React SPAs with provider, hooks, and protected routes.

1|Updated Jun 13, 2017
One-click install
npx skills add https://github.com/RoyMcCrain/dotsfile --skill clerk-react-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clerk-react-patterns
Source: https://github.com/RoyMcCrain/dotsfile/tree/main/claude/skills/clerk-react-patterns
Command: npx skills add https://github.com/RoyMcCrain/dotsfile --skill clerk-react-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill provides a repeatable pattern for integrating Clerk authentication in React SPAs, including provider setup, hooks usage, protected routes, and custom sign-in flows. It reduces boilerplate and ensures consistent auth UX.

Core Features & Use Cases

  • ClerkProvider setup for Vite/CRA apps
  • Hooks: useAuth, useUser, useClerk
  • Protected routes with React Router v6/v7
  • Custom sign-in/up forms using useSignIn/useSignUp
  • Token retrieval with getToken for API calls
  • Flow for organization/profile management when applicable

Quick Start

Install @clerk/react, wrap your app with ClerkProvider at the root, and integrate a simple SignIn/SignOut UI to enable authentication.

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 React SPA?

Set up Clerk authentication in a React SPA by wrapping your root component with ClerkProvider, then integrate hooks like useAuth and useUser to manage user state across Vite or Create React App environments.

How do I create protected routes with Clerk and React Router v6?

Create protected routes with Clerk and React Router v6 by combining the isSignedIn state from useAuth with route guards, redirecting unauthenticated users to a sign-in flow before rendering secure components.

Can I build custom sign-in forms using Clerk hooks in React?

Yes, you can build custom sign-in forms using Clerk hooks in React by leveraging the useSignIn and useSignUp hooks to handle authentication flows directly within your custom UI components.

How do I retrieve auth tokens for API calls with Clerk in React?

Retrieve auth tokens for API calls with Clerk in React by using the getToken method from the useAuth hook, passing the token to your backend API requests for secure session validation.

Does Clerk integration work with both Vite and Create React App?

Yes, Clerk integration works with both Vite and Create React App setups, providing cohesive patterns for provider initialization, routing, and hook usage across different React SPA build tools.

What is the purpose of isLoaded and isSignedIn states in Clerk React hooks?

The isLoaded and isSignedIn states in Clerk React hooks prevent UI flashing and unauthorized access by ensuring authentication data is fully fetched before rendering protected or conditional components.