Open History to see the last commit
1import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
2import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
3
4export interface CloudPublicConfig {
5 readonly clerkPublishableKey: string | null;
6 readonly clerkJwtTemplate: string | null;
7 readonly relayUrl: string | null;
8}
9
10function trimNonEmpty(value: string | undefined): string | null {
11 return value?.trim() || null;
12}
13
14export function resolveCloudPublicConfig(): CloudPublicConfig {
15 return {
16 clerkPublishableKey: trimNonEmpty(
17 import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string | undefined,
18 ),
19 clerkJwtTemplate: trimNonEmpty(import.meta.env.VITE_CLERK_JWT_TEMPLATE as string | undefined),
20 relayUrl: normalizeSecureRelayUrl(
21 (import.meta.env.VITE_T3CODE_RELAY_URL as string | undefined) ?? "",
22 ),
23 };
24}
25
26export function hasCloudPublicConfig(): boolean {
27 const config = resolveCloudPublicConfig();
28 return Boolean(config.clerkPublishableKey && config.clerkJwtTemplate && config.relayUrl);
29}
30
31export function resolveRelayClerkTokenOptions() {
32 const { clerkJwtTemplate } = resolveCloudPublicConfig();
33 if (!clerkJwtTemplate) {
34 throw new Error("T3CODE_CLERK_JWT_TEMPLATE is not configured.");
35 }
36 return relayClerkTokenOptions(clerkJwtTemplate);
37}