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.