-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy path__root.tsx
More file actions
139 lines (134 loc) · 3.68 KB
/
__root.tsx
File metadata and controls
139 lines (134 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import type { Clerk } from "@clerk/clerk-js";
import type { QueryClient } from "@tanstack/react-query";
import {
createRootRouteWithContext,
Outlet,
useNavigate,
} from "@tanstack/react-router";
import { TanStackRouterDevtools } from "@tanstack/react-router-devtools";
import { lazy, type PropsWithChildren, Suspense } from "react";
import { match } from "ts-pattern";
import type {
CloudContext,
CloudNamespaceContext,
EngineContext,
EngineNamespaceContext,
OrganizationContext,
ProjectContext,
} from "@/app/data-providers/cache";
import { DevToolbar } from "@/app/dev-toolbar";
import { FullscreenLoading } from "@/components";
import { clerkPromise } from "@/lib/auth";
import { cloudEnv } from "@/lib/env";
function RootRoute() {
return (
<>
<Outlet />
<DevToolbar />
{import.meta.env.DEV ? (
<TanStackRouterDevtools position="bottom-right" />
) : null}
</>
);
}
const LazyClerkProvider = lazy(() =>
Promise.all([
import("@clerk/clerk-react"),
import("@clerk/themes"),
clerkPromise,
]).then(([{ ClerkProvider }, { dark }, clerk]) => ({
default: ({
children,
navigatePush,
navigateReplace,
}: PropsWithChildren<{
navigatePush: (to: string) => void;
navigateReplace: (to: string) => void;
}>) => (
<ClerkProvider
Clerk={clerk}
appearance={{
baseTheme: dark,
variables: {
colorPrimary: "hsl(var(--primary))",
colorPrimaryForeground:
"hsl(var(--primary-foreground))",
colorTextOnPrimaryBackground:
"hsl(var(--primary-foreground))",
colorBackground: "hsl(var(--background))",
colorInput: "hsl(var(--input))",
colorText: "hsl(var(--text))",
colorTextSecondary: "hsl(var(--muted-foreground))",
borderRadius: "var(--radius)",
colorModalBackdrop: "rgb(0 0 0 / 0.8)",
},
}}
publishableKey={cloudEnv().VITE_APP_CLERK_PUBLISHABLE_KEY}
routerPush={(to: string) => navigatePush(to)}
routerReplace={(to: string) => navigateReplace(to)}
signInUrl="/login"
signUpUrl="/join"
signInForceRedirectUrl="/sso-callback"
signUpForceRedirectUrl="/sso-callback"
taskUrls={{
"choose-organization": "/onboarding/choose-organization",
}}
>
{children}
</ClerkProvider>
),
})),
);
function CloudRoute() {
const navigate = useNavigate();
return (
<Suspense fallback={<FullscreenLoading />}>
<LazyClerkProvider
navigatePush={(to) => navigate({ to })}
navigateReplace={(to) => navigate({ to, replace: true })}
>
<Outlet />
<DevToolbar />
{import.meta.env.DEV ? (
<TanStackRouterDevtools position="bottom-right" />
) : null}
</LazyClerkProvider>
</Suspense>
);
}
interface RootRouteContext {
/**
* Only available in cloud mode
*/
clerk: Clerk;
queryClient: QueryClient;
getOrCreateCloudContext: (clerk: Clerk) => CloudContext;
getOrCreateEngineContext: (
engineToken: (() => string) | string | (() => Promise<string>),
) => EngineContext;
getOrCreateOrganizationContext: (
parent: CloudContext,
organization: string,
) => OrganizationContext;
getOrCreateProjectContext: (
parent: CloudContext & OrganizationContext,
organization: string,
project: string,
) => ProjectContext;
getOrCreateCloudNamespaceContext: (
parent: CloudContext & OrganizationContext & ProjectContext,
namespace: string,
engineNamespaceName: string,
engineNamespaceId: string,
) => CloudNamespaceContext;
getOrCreateEngineNamespaceContext: (
parent: EngineContext,
namespace: string,
) => EngineNamespaceContext;
}
export const Route = createRootRouteWithContext<RootRouteContext>()({
component: match(__APP_TYPE__)
.with("cloud", () => CloudRoute)
.otherwise(() => RootRoute),
pendingComponent: FullscreenLoading,
});