clerk-tanstack-patterns

Implement Clerk authentication patterns in TanStack React Start applications.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Adding authentication to TanStack React Start apps requires coordinating server functions, route guards, loaders, and the Vinxi server runtime, and mistakes like wrong import paths or missing middleware cause silent auth failures. ## Core Features & Use Cases - Route Protection: Guard routes with beforeLoad checks that call auth() inside createServerFn and throw redirects for unauthenticated users. - Server-Side Auth: Use auth() from @clerk/tanstack-react-start/server in server functions, loaders, and API routes to access userId and orgId. - Vinxi Setup: Register clerkMiddleware in start.ts and wrap the root route with ClerkProvider so auth state flows through every request. - Use Case: You need to protect all /app/* routes with a single layout guard, pass userId through route context to loaders, and fetch org-scoped data only when an organization is active. ## Quick Start Ask the AI to protect the /dashboard route in your TanStack Start app so unauthenticated users are redirected to /sign-in.

Frequently Asked Questions about clerk-tanstack-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I protect a route in TanStack Start with Clerk?▼

Create a createServerFn that calls auth() from @clerk/tanstack-react-start/server, throw redirect({ to: '/sign-in' }) when isAuthenticated is false, and call that function in the route's beforeLoad. Child routes of a guarded layout route inherit the protection automatically.

How to use auth() in TanStack createServerFn?▼

Import auth from @clerk/tanstack-react-start/server inside your createServerFn handler and await it to get isAuthenticated, userId, and orgId. Throw an error or redirect when the user is not authenticated, then return the auth data for loaders or components.

Why does auth() return an empty object in TanStack Start?▼

An empty auth() result means clerkMiddleware is not registered in src/start.ts. Add clerkMiddleware() to the requestMiddleware array in createStart so Clerk auth state is attached to every incoming request.

What is the difference between server and client imports in @clerk/tanstack-react-start?▼

Server-side auth() and clerkMiddleware must be imported from @clerk/tanstack-react-start/server, while client hooks like useAuth and useUser come from the package root. Mixing these import paths causes runtime errors.

How do I pass userId from beforeLoad to a loader in TanStack Router?▼

Return an object containing userId from beforeLoad, then access it in the loader through the context parameter. The route component reads the loader result with Route.useLoaderData().

Can I protect a TanStack Start API route with Clerk?▼

Yes, call auth() from @clerk/tanstack-react-start/server inside the API route handler and return a 401 Response when isAuthenticated is false. Do not use client-side hooks in server handlers.