11import type { Clerk } from "@clerk/clerk-js" ;
2+ import * as Sentry from "@sentry/react" ;
23import type { QueryClient } from "@tanstack/react-query" ;
34import { createRootRouteWithContext , Outlet } from "@tanstack/react-router" ;
45import { TanStackRouterDevtools } from "@tanstack/react-router-devtools" ;
56import posthog from "posthog-js" ;
6- import { FullscreenLoading } from "@/components " ;
7+ import { match } from "ts-pattern " ;
78
89function RootRoute ( ) {
910 return (
@@ -26,27 +27,40 @@ interface RootRouteContext {
2627
2728export const Route = createRootRouteWithContext < RootRouteContext > ( ) ( {
2829 component : RootRoute ,
29- pendingComponent : FullscreenLoading ,
3030 beforeLoad : async ( { context } ) => {
31- if ( ! context . clerk ) return ;
31+ return match ( __APP_TYPE__ )
32+ . with ( "cloud" , async ( ) => {
33+ if ( ! context . clerk ) return ;
3234
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 ;
4337 }
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
4964 } ) ;
50- } ) ;
5165 } ,
5266} ) ;
0 commit comments