Files
t3code/apps/web/src/cloud/publicConfig.ts
T
2026-06-03 23:48:05 -07:00

39 lines
1.2 KiB
TypeScript

import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
export interface CloudPublicConfig {
readonly clerkPublishableKey: string | null;
readonly clerkJwtTemplate: string | null;
readonly relayUrl: string | null;
}
function trimNonEmpty(value: string | undefined): string | null {
return value?.trim() || null;
}
export function resolveCloudPublicConfig(): CloudPublicConfig {
return {
clerkPublishableKey: trimNonEmpty(
import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string | undefined,
),
clerkJwtTemplate: trimNonEmpty(import.meta.env.VITE_CLERK_JWT_TEMPLATE as string | undefined),
relayUrl:
trimNonEmpty(import.meta.env.VITE_T3CODE_RELAY_URL as string | undefined)?.replace(
/\/+$/u,
"",
) ?? null,
};
}
export function hasCloudPublicConfig(): boolean {
const config = resolveCloudPublicConfig();
return Boolean(config.clerkPublishableKey && config.clerkJwtTemplate && config.relayUrl);
}
export function resolveRelayClerkTokenOptions() {
const { clerkJwtTemplate } = resolveCloudPublicConfig();
if (!clerkJwtTemplate) {
throw new Error("T3CODE_CLERK_JWT_TEMPLATE is not configured.");
}
return relayClerkTokenOptions(clerkJwtTemplate);
}