Skip to content
5 changes: 5 additions & 0 deletions .changeset/tanstack-start-csrf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"clerk": patch
---

Register TanStack Start's CSRF middleware before Clerk's middleware in `src/start.ts`, both when `clerk init` creates the file and when it can safely edit an existing one. This needs `@tanstack/react-start` 1.168.10 or later; otherwise `clerk init` prints the manual steps instead.
14 changes: 8 additions & 6 deletions packages/cli-core/src/commands/init/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ Nuxt's module system auto-configures middleware and auto-imports components.

### TanStack Start

| Action | File | Description |
| ------ | -------------------------- | ------------------------------------------- |
| MODIFY | `src/start.ts` | Add `clerkMiddleware` to request middleware |
| MODIFY | `src/routes/__root.tsx` | Add `ClerkProvider` and wrap body contents |
| CREATE | `src/routes/sign-in.$.tsx` | Sign-in route with `<SignIn />` component |
| CREATE | `src/routes/sign-up.$.tsx` | Sign-up route with `<SignUp />` component |
| Action | File | Description |
| ------------- | -------------------------- | ----------------------------------------------- |
| CREATE/MODIFY | `src/start.ts` | Register CSRF middleware, then Clerk middleware |
| MODIFY | `src/routes/__root.tsx` | Add `ClerkProvider` and wrap body contents |
| CREATE | `src/routes/sign-in.$.tsx` | Sign-in route with `<SignIn />` component |
| CREATE | `src/routes/sign-up.$.tsx` | Sign-up route with `<SignUp />` component |

CSRF middleware needs `@tanstack/react-start` 1.168.10 or later, with `@tanstack/react-router` 1.170.7 or later. When the version is older or can't be confirmed, or an existing `start.ts` can't be edited safely, `clerk init` leaves the file unchanged and prints the manual steps.

### Astro

Expand Down
Loading
Loading