Skip to content

Commit 773b88f

Browse files
authored
feat(tanstack-start): Throw more useful error when clerkHandler is not configured (clerk#3918)
1 parent 6bd0f7f commit 773b88f

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

.changeset/rotten-mangos-hear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/tanstack-start": minor
3+
---
4+
5+
Throw a more useful error when `clerkHandler()` is not configured in the SSR entrypoint

packages/tanstack-start/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ function RootComponent() {
119119
function RootDocument({ children }: { children: React.ReactNode }) { ... }
120120
```
121121

122-
Also you will need to make on more modification to `app/ssr.tsx`:
122+
### Setup `clerkHandler` in the SSR entrypoint
123+
124+
You will also need to make on more modification to you SSR entrypoint (default: `app/ssr.tsx`):
123125

124126
- Wrap the `createStartHandler` with `createClerkHandler`
125127

packages/tanstack-start/src/client/ClerkProvider.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ import { useRouteContext } from '@tanstack/react-router';
33
import { Asset } from '@tanstack/start';
44
import { useEffect } from 'react';
55

6-
import { isClient } from '../utils';
6+
import { errorThrower, isClient } from '../utils';
7+
import { clerkHandlerNotConfigured } from '../utils/errors';
78
import { ClerkOptionsProvider } from './OptionsContext';
89
import type { TanstackStartClerkProviderProps } from './types';
910
import { useAwaitableNavigate } from './useAwaitableNavigate';
1011

12+
export * from '@clerk/clerk-react';
13+
1114
const SDK_METADATA = {
1215
name: PACKAGE_NAME,
1316
version: PACKAGE_VERSION,
1417
};
1518

16-
export * from '@clerk/clerk-react';
17-
1819
const awaitableNavigateRef: { current: ReturnType<typeof useAwaitableNavigate> | undefined } = { current: undefined };
1920

2021
export function ClerkProvider({ children, ...providerProps }: TanstackStartClerkProviderProps): JSX.Element {
@@ -27,6 +28,10 @@ export function ClerkProvider({ children, ...providerProps }: TanstackStartClerk
2728
awaitableNavigateRef.current = awaitableNavigate;
2829
}, [awaitableNavigate]);
2930

31+
if (!routerContext?.clerkInitialState?.__internal_clerk_state) {
32+
errorThrower.throw(clerkHandlerNotConfigured);
33+
}
34+
3035
const clerkInitState = isClient() ? (window as any).__clerk_init_state : routerContext?.clerkInitialState;
3136

3237
const {

packages/tanstack-start/src/utils/errors.ts

+8
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ export const noFetchFnCtxPassedInGetAuth = createErrorMessage(`
1616
...
1717
});
1818
`);
19+
20+
export const clerkHandlerNotConfigured = createErrorMessage(`
21+
It looks like you're trying to use Clerk without configuring the Clerk handler.
22+
23+
To fix this, make sure you have the \`clerkHandler()\` configure in you SSR entry file (example: app/ssr.tsx).
24+
25+
For more info, check out the docs: https://github.com/clerk/javascript/tree/main/packages/tanstack-start#setup-clerkhandler-in-the-ssr-entrypoint,
26+
`);

0 commit comments

Comments
 (0)