The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 32 lines 1.17 KB
Raw
1 import { ClerkProvider, getClerkInstance } from "@clerk/expo";
2 import { tokenCache } from "@clerk/expo/token-cache";
3 import type { ReactNode } from "react";
4
5 import { cloudAccountService, deactivateCloudRelayAccount } from "./cloudAccountService";
6 import { resolveCloudPublicConfig } from "./publicConfig";
7
8 const cloudConfig = resolveCloudPublicConfig();
9 // Build-time constant: null when this build has no cloud config.
10 const publishableKey = cloudConfig.relay.url ? cloudConfig.clerk.publishableKey : null;
11
12 if (publishableKey) {
13 // The same native singleton ClerkProvider renders with, so the service
14 // observes it for the app's lifetime without a React subscription.
15 cloudAccountService.attach(getClerkInstance({ publishableKey }));
16 } else {
17 // Without cloud config no account can ever activate, so drop anything a
18 // previous build with cloud enabled left registered.
19 deactivateCloudRelayAccount();
20 }
21
22 export function CloudAuthProvider(props: { readonly children: ReactNode }) {
23 if (!publishableKey) {
24 return props.children;
25 }
26
27 return (
28 <ClerkProvider publishableKey={publishableKey} tokenCache={tokenCache}>
29 {props.children}
30 </ClerkProvider>
31 );
32 }