midudev/autoskills/clerk-tanstack-patterns

Claude Code and agent skill by midudev/autoskills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

'TanStack React Start auth patterns with @clerk/tanstack-react-start

Install

npx vskill@latest install midudev/autoskills/clerk-tanstack-patterns

SKILL.md

TanStack React Start Patterns

What Do You Need?

TaskReference
Protect routes with beforeLoadreferences/router-guards.md
Auth in createServerFnreferences/server-functions.md
Pass auth to loadersreferences/loaders.md
Configure Vite + Clerk middlewarereferences/server-setup.md

References

ReferenceDescription
references/router-guards.mdbeforeLoad auth redirect
references/server-functions.mdcreateServerFn with auth()
references/loaders.mdAuth context in loaders
references/server-setup.mdVite and request middleware setup

Setup

npm install @clerk/tanstack-react-start

.env:

VITE_CLERK_PUBLISHABLE_KEY=pk_...
CLERK_SECRET_KEY=sk_...

src/start.ts (request middleware):

typescript
import { clerkMiddleware } from '@clerk/tanstack-react-start/server'
import { createCsrfMiddleware, createStart } from '@tanstack/react-start'
const csrfMiddleware = createCsrfMiddleware({
filter: (ctx) => ctx.handlerType === 'serverFn',
})
export const startInstance = createStart(() => {
return {
requestMiddleware: [csrfMiddleware, clerkMiddleware()],
}
})

src/routes/__root.tsx — wrap with <ClerkProvider>:

tsx
import { ClerkProvider } from '@clerk/tanstack-react-start'
function RootDocument({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<ClerkProvider>
{children}
</ClerkProvider>
</body>
</html>
)
}

Mental Model

TanStack Start uses the tanstackStart() Vite plugin. Register CSRF protection before Clerk request middleware in src/start.ts; auth then flows through two layers:

  1. Server layer — createServerFn + auth() from @clerk/tanstack-react-start/server
  2. Router layer — beforeLoad on route definitions, throws redirect for unauthenticated

Both layers are server-executed. Client hooks (useAuth, useUser) are React hooks for the browser side.

Minimal Pattern

typescript
import { createFileRoute, redirect } from '@tanstack/react-router'
import { createServerFn } from '@tanstack/react-start'
import { auth } from '@clerk/tanstack-react-start/server'
const authStateFn = createServerFn().handler(async () => {
const { isAuthenticated, userId } = await auth()
if (!isAuthenticated) {
throw redirect({ to: '/sign-in' })
}
return { userId }
})
export const Route = createFileRoute('/dashboard')({
beforeLoad: async () => await authStateFn(),
})

Common Pitfalls

SymptomCauseFix
auth() throws "without configuring the middleware"Missing clerkMiddleware in start.tsAdd it after CSRF middleware in requestMiddleware
redirect not thrownUsing return instead of throwthrow redirect(...) in TanStack
Wrong import for authMixing client/server importsServer: @clerk/tanstack-react-start/server
Loader context missing userIdNot passing from beforeLoadReturn from beforeLoad, access via context
ClerkProvider missingForgot root wrappingAdd to __root.tsx shell component

See Also

  • clerk-setup - Initial Clerk install
  • clerk-custom-ui - Custom flows & appearance
  • clerk-orgs - B2B organizations

Docs

TanStack React Start SDK

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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/midudev/autoskills/clerk-tanstack-patterns/badge)](https://verified-skill.com/skills/midudev/autoskills/clerk-tanstack-patterns)

Something wrong with this skill or its page? Tell us.