clerk-tanstack-patterns
/clerk-tanstack-patterns
Podpowiada wzorce Clerk w TanStack React Start: createServerFn, guardy beforeLoad, loadery, plugin Vite i middleware serwera.
- Autor
- midudev ↗
- Repozytorium
- autoskills ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 12.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 13
- Skrypty
- 5
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 1
Brak sygnałów. Repozytorium zmienione 12.11.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
- 5 skryptów w paczce. Przejrzyj je przed instalacją, bo Claude może je uruchomić.
Skrypty: templates/tanstack-basic-auth/src/router.tsx, templates/tanstack-basic-auth/src/routes/__root.tsx, templates/tanstack-basic-auth/src/routes/index.tsx, templates/tanstack-basic-auth/src/start.ts, templates/tanstack-basic-auth/vite.config.ts
Co robi i kiedy
Podpowiada wzorce Clerk w TanStack React Start: createServerFn, guardy beforeLoad, loadery, plugin Vite i middleware serwera.
Oryginalny opis (EN)
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.
Jak działa
- What Do You Need?
- References
- Setup
- Mental Model
- Minimal Pattern
- Common Pitfalls
- See Also
- Docs
Podgląd SKILL.md
---
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)
Pliki w paczce (13)
- SKILL.md 4 KB
- evals/evals.json 5 KB
- references/loaders.md 2 KB
- references/router-guards.md 2 KB
- references/server-functions.md 2 KB
- references/server-setup.md 3 KB
- templates/tanstack-basic-auth/package.json 1 KB
- templates/tanstack-basic-auth/tsconfig.json 1 KB
- templates/tanstack-basic-auth/vite.config.ts 1 KB
- templates/tanstack-basic-auth/src/router.tsx 1 KB
- templates/tanstack-basic-auth/src/start.ts 1 KB
- templates/tanstack-basic-auth/src/routes/__root.tsx 1 KB
- templates/tanstack-basic-auth/src/routes/index.tsx 1 KB
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · midudev/autoskills | 100 | MIT |
| growupanand/ConvoForm | 100 | Apache-2.0 |
| clerk/skills | 100 | MIT |
Migawka bazy z 13.11.2026 · wersja paczki 09572684166c (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100tanstack-router
Obejmuje routing plikowy TanStack Router w React: definicje tras, layouty, guardy uwierzytelniania, loadery i typowaną nawigację. - 100tanstack-start
Podpowiada dobre praktyki TanStack Start: server functions z createServerFn, SSR ze streamingiem, API routes, app.config.ts oraz wdrożenie na Node, Vercel, Netlify, Bun i Cloudflare. - 100tanstack-router
Pomaga definiować trasy przez createFileRoute, walidować search params w Zod, pisać loadery, ustawiać auth guards w beforeLoad i podłączać TanStack Query do loaderów. - 95tanstack-start-best-practices
Podpowiada dobre praktyki TanStack Start: funkcje serwerowe, middleware, SSR, uwierzytelnianie i wdrożenie aplikacji fullstack. - 90clerk-auth
Pokazuje wzorce uwierzytelniania Clerk: middleware, organizacje, webhooki i synchronizację użytkowników. - 100clerk-nuxt-patterns
Podpowiada wzorce uwierzytelniania Clerk w Nuxt 3: middleware, composable, trasy API po stronie serwera i ochronę tras.