Skip to content

Commit 6dd884f

Browse files
authored
chore: add changeset
1 parent c2faffe commit 6dd884f

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

.changeset/itchy-zoos-shake.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
"@clerk/tanstack-react-start": minor
3+
---
4+
5+
Reuses existing `Auth` object from the server handler
6+
7+
The `createClerkHandler` helper now returns a Promise and requires awaiting during setup to ensure authentication context is available at the earliest possible point in the request lifecycle, before any router loaders or server functions execute
8+
9+
```ts
10+
// server.ts
11+
import { createStartHandler, defineHandlerCallback, defaultStreamHandler } from '@tanstack/react-start/server';
12+
import { createRouter } from './router';
13+
import { createClerkHandler } from '@clerk/tanstack-react-start/server';
14+
15+
const handlerFactory = createClerkHandler(
16+
createStartHandler({
17+
createRouter,
18+
}),
19+
);
20+
21+
export default defineHandlerCallback(async event => {
22+
const startHandler = await handlerFactory(defaultStreamHandler); // awaited
23+
return startHandler(event);
24+
});
25+
```
26+
27+
`getAuth()` is now sync and no longer requires awaiting
28+
29+
```ts
30+
import { getAuth } from '@clerk/tanstack-react-start/server'
31+
32+
const authStateFn = createServerFn({ method: 'GET' }).handler(() => {
33+
const request = getWebRequest()
34+
35+
const auth = getAuth(request) // no await
36+
37+
return { userId: auth.userId }
38+
})
39+
```

0 commit comments

Comments
 (0)