1
1
import type { Clerk } from "@clerk/clerk-js" ;
2
+ import * as Sentry from "@sentry/react" ;
2
3
import type { QueryClient } from "@tanstack/react-query" ;
3
4
import { createRootRouteWithContext , Outlet } from "@tanstack/react-router" ;
4
5
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools" ;
5
6
import posthog from "posthog-js" ;
6
- import { FullscreenLoading } from "@/components " ;
7
+ import { match } from "ts-pattern " ;
7
8
8
9
function RootRoute ( ) {
9
10
return (
@@ -26,27 +27,40 @@ interface RootRouteContext {
26
27
27
28
export const Route = createRootRouteWithContext < RootRouteContext > ( ) ( {
28
29
component : RootRoute ,
29
- pendingComponent : FullscreenLoading ,
30
30
beforeLoad : async ( { context } ) => {
31
- if ( ! context . clerk ) return ;
31
+ return match ( __APP_TYPE__ )
32
+ . with ( "cloud" , async ( ) => {
33
+ if ( ! context . clerk ) return ;
32
34
33
- // wait for Clerk
34
- await new Promise ( ( resolve , reject ) => {
35
- context . clerk . on ( "status" , ( payload ) => {
36
- if ( payload === "ready" ) {
37
- posthog . setPersonProperties ( {
38
- id : context . clerk . user ?. id ,
39
- email : context . clerk . user ?. primaryEmailAddress
40
- ?. emailAddress ,
41
- } ) ;
42
- return resolve ( true ) ;
35
+ if ( context . clerk . status === "ready" ) {
36
+ return ;
43
37
}
44
- // If the status is not "ready", we don't resolve the promise
45
- // We can also add a timeout to avoid waiting indefinitely
46
- setTimeout ( ( ) => {
47
- reject ( new Error ( "Can't confirm identity" ) ) ;
48
- } , 10000 ) ;
38
+
39
+ // Wait for Clerk
40
+ await new Promise ( ( resolve , reject ) => {
41
+ context . clerk . on ( "status" , ( payload ) => {
42
+ if ( payload === "ready" ) {
43
+ Sentry . setUser ( {
44
+ id : context . clerk . user ?. id ,
45
+ email : context . clerk . user ?. primaryEmailAddress
46
+ ?. emailAddress ,
47
+ } ) ;
48
+ posthog . setPersonProperties ( {
49
+ id : context . clerk . user ?. id ,
50
+ email : context . clerk . user ?. primaryEmailAddress
51
+ ?. emailAddress ,
52
+ } ) ;
53
+ return resolve ( true ) ;
54
+ }
55
+ } ) ;
56
+ // Timeout to avoid waiting indefinitely
57
+ setTimeout ( ( ) => {
58
+ reject ( new Error ( "Can't confirm identity" ) ) ;
59
+ } , 10000 ) ;
60
+ } ) ;
61
+ } )
62
+ . otherwise ( ( ) => {
63
+ // No-op for engine and inspector
49
64
} ) ;
50
- } ) ;
51
65
} ,
52
66
} ) ;
0 commit comments