midudev/autoskills/clerk-react-router-patterns
Claude Code and agent skill by midudev/autoskills
- community
Checking that the SKILL.md file is still in the repository.
'React Router v7/v8 patterns with Clerk — rootAuthLoader, getAuth in loaders,
Install
npx vskill@latest install midudev/autoskills/clerk-react-router-patternsSKILL.md
The same SKILL.md was published earlier as midudev/autoskills/clerk-react-router-patterns.
React Router Patterns
SDK: @clerk/react-router v3.5+. Supports React Router v7.9+ and v8.
What Do You Need?
| Task | Reference | |
|---|---|---|
| Auth in loaders and actions | references/loaders-actions.md | |
| Protected routes and redirects | references/protected-routes.md | |
| SSR user data and session | references/ssr-auth.md |
React Router v7 vs v8
Check the installed react-router major version before scaffolding — the config differs:
| v7.9+ | v8+ | ||
|---|---|---|---|
| Middleware API | Opt-in: set future: { v8_middleware: true } in react-router.config.ts | Always on — do NOT set the flag (v8 removed it) | |
ssr.noExternal workaround (below) | Not needed | Required |
Minimal Setup
1. vite.config.ts (v8 only — REQUIRED)
React Router v8 ships development/production conditional exports. In react-router dev, Vite externalizes @clerk/react-router for SSR, so Node resolves the production build of react-router while the app code gets the development build — two module instances, two Router contexts. Every request then fails during SSR with:
`npm ls react-router` shows a single copy — that does NOT rule this out. The duplication is per export condition, not per installed copy. Do not chase duplicate installs; add the workaround (upstream issue: https://github.com/remix-run/react-router/issues/15232):
2. root.tsx
There is no ClerkApp HOC in @clerk/react-router (that was the @clerk/remix API). Render <ClerkProvider loaderData={loaderData}> inside the default export and pass it the root route's loaderData.
3. react-router.config.ts (v7 only)
On v8, omit the future block entirely — the flag no longer exists.
Required:rootAuthLoadermust be called inroot.tsx's loader. Without it,getAuththrows in nested loaders.
Mental Model
React Router v7/v8 uses a middleware + loader pipeline. Clerk plugs into both layers:
- Middleware (
clerkMiddleware()) — runs on every request, attaches auth to context - `rootAuthLoader` — required in
root.tsxto pass Clerk state to the client - `getAuth(args)` — called inside any loader/action to get the current user
Auth in Loaders
Auth in Actions
Client Components
Org Switching
Common Pitfalls
| Symptom | Cause | Fix | |
|---|---|---|---|
useNavigate() may be used only in the context of a <Router> thrown from ClerkProvider during SSR in dev (v8) | Vite dev SSR externalizes @clerk/react-router, which then loads react-router's production build while the app uses the development build — two Router contexts. A single copy in npm ls does not rule this out. | Add ssr: { noExternal: ['@clerk/react-router'] } to vite.config.ts. Do NOT downgrade to v7 | |
Build error: ClerkApp is not exported | ClerkApp does not exist in @clerk/react-router | Use <ClerkProvider loaderData={loaderData}> in root.tsx's default export | |
clerkMiddleware() not detected | Missing middleware (or on v7, missing v8_middleware future flag) | Export middleware = [clerkMiddleware()] from root route; on v7 also set future: { v8_middleware: true } | |
| Unknown future flag error/warning (v8) | v8_middleware flag left in react-router.config.ts after upgrading | Remove the future.v8_middleware entry — middleware is always on in v8 | |
getAuth returns empty userId | rootAuthLoader not called | Call rootAuthLoader(args) in root.tsx loader | |
| Infinite redirect loop | Redirect target is also protected | Exclude /sign-in from protection check | |
redirect not working in action | Using Response instead of throw redirect() | Use throw redirect('/path') from react-router |
Import Map
| What | Import From | |
|---|---|---|
getAuth | @clerk/react-router/server | |
rootAuthLoader | @clerk/react-router/server | |
clerkMiddleware | @clerk/react-router/server | |
ClerkProvider | @clerk/react-router | |
useAuth, useUser | @clerk/react-router | |
OrganizationSwitcher | @clerk/react-router |
See Also
clerk-setup- Initial Clerk installclerk-custom-ui- Custom flows & appearanceclerk-orgs- B2B organizations
Docs
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpackages/autoskills/skills-registry/clerk-react-router-patterns/SKILL.md
Popularity
- Repository stars
- 6,099
- Repository forks
- 561
- 7-day trend score
- 44
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/midudev/autoskills/clerk-react-router-patterns)