clerk-tanstack-patterns
This skill provides authentication patterns for TanStack React Start applications using Clerk.
Identity proven by GitHub's verified organisation badge (clerk)
- Agents
- Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode
- License
- MIT (permissive)
- Pin
- a02dbd2pinned Oct 9, 2026
- Context cost
- about 860 tokenswhen the skill loads
- GitHub stars
- 86on clerk/skills
- Scripts
- 2 scripts
What it does
“TanStack React Start auth patterns with @clerk/tanstack-react-start - createServerFn, beforeLoad guards, loaders, Vite plugin, server middleware. Triggers on: TanStack auth, createServerFn clerk, beforeLoad protection, TanStack Start middleware.”
Generated summary from the skill's own text
This skill provides authentication patterns for TanStack React Start applications using Clerk. It covers protecting routes with beforeLoad guards, handling auth in server functions, configuring middleware, and wrapping the app with ClerkProvider for full-stack auth integration.
When to use it
- Building TanStack React Start apps requiring authentication
- Protecting routes with server-side beforeLoad auth checks
- Accessing user identity in createServerFn server functions
- Setting up Clerk middleware and CSRF protection in Vite
When not to
- Using client-only auth without server functions
- Applications not using TanStack React Start framework
- When Clerk is not your chosen auth provider
Install
These commands install from the publisher's repository and need no account.
skills CLI
npx skills add clerk/skills --skill clerk-tanstack-patternsInstalls from the repository's default branch, which may have changed since the commit we checked.
GitHub CLI 2.90 or later
gh skill install clerk/skills clerk-tanstack-patterns@a02dbd2a933b8929525129a6cb9dcf6ed66d0adfInstalls the commit we checked (a02dbd2).
Copy by hand
Download the folder at a02dbd2 and put it in .claude/skills/clerk-tanstack-patterns for Claude Code and in .agents/skills/clerk-tanstack-patterns for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode.
Copy for your agent
A prompt for any coding agent. It installs this skill from GitHub at the pinned commit, copies the files as they are, and runs nothing unless you ask.
Prompt
Install the agent skill "clerk-tanstack-patterns" by Clerk. Source, pinned to commit a02dbd2a933b8929525129a6cb9dcf6ed66d0adf: https://github.com/clerk/skills/tree/a02dbd2a933b8929525129a6cb9dcf6ed66d0adf/skills/clerk-tanstack-patterns 1. Download that folder at exactly this commit. Do not use the default branch. 2. Copy every file unchanged, keeping the folder structure, into .claude/skills/clerk-tanstack-patterns/ for Claude Code and .agents/skills/clerk-tanstack-patterns/ for Codex, Cursor, Gemini CLI, GitHub Copilot and OpenCode. Create the folders if they do not exist. 3. Do not edit the files, and do not run any script in the folder unless I ask you to. 4. When you are done, list the files you copied and where you put them. Listing and checks: https://www.agentnative.dev/skills/clerk/clerk-tanstack-patterns
SKILL.md at the pin
---
name: clerk-tanstack-patterns
description: 'TanStack React Start auth patterns with @clerk/tanstack-react-start
- createServerFn, beforeLoad guards, loaders, Vite plugin, server middleware. Triggers on: TanStack
auth, createServerFn clerk, beforeLoad protection, TanStack Start middleware.'
license: MIT
allowed-tools: WebFetch
metadata:
author: clerk
version: 1.0.0
---
# TanStack React Start Patterns
## What Do You Need?
| Task | Reference |
|------|-----------|
| Protect routes with beforeLoad | references/router-guards.md |
| Auth in createServerFn | references/server-functions.md |
| Pass auth to loaders | references/loaders.md |
| Configure Vite + Clerk middleware | references/server-setup.md |
## References
| Reference | Description |
|-----------|-------------|
| `references/router-guards.md` | beforeLoad auth redirect |
| `references/server-functions.md` | createServerFn with auth() |
| `references/loaders.md` | Auth context in loaders |
| `references/server-setup.md` | Vite 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
| Symptom | Cause | Fix |
|---------|-------|-----|
| `auth()` throws "without configuring the middleware" | Missing `clerkMiddleware` in start.ts | Add it after CSRF middleware in `requestMiddleware` |
| `redirect` not thrown | Using `return` instead of `throw` | `throw redirect(...)` in TanStack |
| Wrong import for `auth` | Mixing client/server imports | Server: `@clerk/tanstack-react-start/server` |
| Loader context missing userId | Not passing from beforeLoad | Return from beforeLoad, access via `context` |
| `ClerkProvider` missing | Forgot root wrapping | Add 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](https://clerk.com/docs/tanstack-react-start/getting-started/quickstart)
From clerk/skills at a02dbd2, shown as plain text under its license: MIT (permissive). The license text is in skills/clerk-tanstack-patterns/SKILL.md.
View SKILL.md on GitHub at a02dbd2Files
- SKILL.md3.8 KB · 79dea360d33f
- evals/
- evals.json5.3 KB · 1aafd554e380
- references/
- loaders.md1.8 KB · 35a62a7840ce
- router-guards.md2.1 KB · fbe6db72ebea
- server-functions.md2.2 KB · 115bda939576
- server-setup.md2.7 KB · e2dc963921dc
- templates/
- tanstack-basic-auth/
- package.json513 B · 71c4bded8f70
- src/
- router.tsx488 B · b608db26eb89
- routes/
- __root.tsx808 B · d14a8543e397
- index.tsx496 B · e63e09605707
- start.ts372 B · 00412e96b38a
- tsconfig.json531 B · cd0440ff9801
- vite.config.ts383 B · bf760d0220bb
13 files, 21 KB in total. Each file has a sha256 in the pin's manifest; the first 12 characters are shown.
Skill folder on GitHub at a02dbd2More from Clerk
audit-clerk-skill
Audits the bundled clerk-cli skill against the Clerk CLI source repository, comparing commands, flags, and agent-mode behavior to detect drift, gaps, and…
Claude Code · about 1.9K tokens · pinned 6 days ago
audit-expo-skill
Audits the clerk-expo skill against the @clerk/expo SDK source and clerk-docs to detect API drift, missing coverage, and stale claims.
Claude Code · about 2.2K tokens · pinned 6 days ago
clerk
This skill routes Clerk authentication tasks to specialized sub-skills based on the user's specific need, such as framework setup, CLI operations, custom UI…
Claude Code, Codex, Cursor +4 · about 1.4K tokens · pinned 6 days ago
clerk-android
This skill implements Clerk authentication in native Android apps written in Kotlin and Jetpack Compose by following the clerk-android SDK patterns and…
Claude Code, Codex, Cursor +4 · about 2K tokens · pinned 6 days ago
clerk-astro-patterns
This skill teaches the agent to integrate Clerk authentication into Astro applications using middleware, SSR pages, island components, and API routes.
Contains scripts
Claude Code, Codex, Cursor +3 · about 850 tokens · pinned 6 days ago
clerk-billing
Clerk Billing enables subscription management in SaaS apps by rendering pricing tables and checkout drawers, configuring plans with feature entitlements, and…
Claude Code, Codex, Cursor +4 · about 4.9K tokens · pinned 6 days ago
Related in Backend and APIs
supabase
This skill enables the agent to work with Supabase products including Database, Auth, Edge Functions, Realtime, Storage, and Vectors.
by SupabaseOfficial publisher
Claude Code, Codex, Cursor +4 · about 3.3K tokens · pinned 6 days ago
airflow-plugins
Builds Airflow 3.1+ plugins that embed FastAPI apps, custom UI pages, React components, middleware, macros, and operator links directly into the Airflow UI…
by AstronomerOfficial publisher
Claude Code, Codex, Cursor +4 · about 5.8K tokens · pinned 6 days ago
databricks-apps-python
Enables agents to build Python backends for Databricks Apps using FastAPI, Flask, Dash, Streamlit, Gradio, or Reflex.
by DatabricksOfficial publisher
Contains scripts
Claude Code, Codex, Cursor +3 · about 2.9K tokens · pinned 6 days ago
flags-sdk
The Flags SDK is a feature flags toolkit for Next.js and SvelteKit that declares flags as functions and evaluates them server-side.
by VercelOfficial publisher
Claude Code, Codex, Cursor +3 · about 5.8K tokens · pinned 6 days ago
clerk-nextjs-patterns
This skill teaches advanced Next.js patterns for protecting routes, Server Actions, and API endpoints with Clerk authentication.
by ClerkOfficial publisher
Contains scripts
Claude Code, Codex, Cursor +3 · about 2.1K tokens · pinned 6 days ago
clerk-nuxt-patterns
This skill teaches agents how to implement authentication in Nuxt 3 applications using the Clerk SDK.
by ClerkOfficial publisher
Contains scripts
Claude Code, Codex, Cursor +3 · about 710 tokens · pinned 6 days ago