Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/mobile/src/features/cloud/publicConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, expect, it, vi } from "vite-plus/test";

import { hasTracingPublicConfig, resolveCloudPublicConfig } from "./publicConfig";
import {
CloudPublicConfigMissingError,
hasTracingPublicConfig,
resolveCloudPublicConfig,
resolveRelayClerkTokenOptions,
} from "./publicConfig";

vi.mock("expo-constants", () => ({
default: {
Expand All @@ -11,6 +16,12 @@ vi.mock("expo-constants", () => ({
}));

describe("resolveCloudPublicConfig", () => {
it("reports the missing Clerk JWT template as structured configuration", () => {
expect(() => resolveRelayClerkTokenOptions()).toThrowError(
new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" }),
);
});

it("returns no cloud configuration for an unconfigured build", () => {
expect(resolveCloudPublicConfig({})).toEqual({
clerk: {
Expand Down
14 changes: 13 additions & 1 deletion apps/mobile/src/features/cloud/publicConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import Constants from "expo-constants";
import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
import * as Schema from "effect/Schema";

export class CloudPublicConfigMissingError extends Schema.TaggedErrorClass<CloudPublicConfigMissingError>()(
"CloudPublicConfigMissingError",
{
key: Schema.Literal("T3CODE_CLERK_JWT_TEMPLATE"),
},
) {
override get message(): string {
return `${this.key} is not configured.`;
}
}

export interface CloudPublicConfig {
readonly clerk: {
Expand Down Expand Up @@ -87,7 +99,7 @@ export function hasTracingPublicConfig(
export function resolveRelayClerkTokenOptions() {
const { jwtTemplate } = resolveCloudPublicConfig().clerk;
if (!jwtTemplate) {
throw new Error("T3CODE_CLERK_JWT_TEMPLATE is not configured.");
throw new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" });
}
return relayClerkTokenOptions(jwtTemplate);
}
14 changes: 13 additions & 1 deletion apps/web/src/cloud/publicConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { afterEach, describe, expect, it, vi } from "vite-plus/test";

import { hasCloudPublicConfig } from "./publicConfig.ts";
import {
CloudPublicConfigMissingError,
hasCloudPublicConfig,
resolveRelayClerkTokenOptions,
} from "./publicConfig.ts";

afterEach(() => {
vi.unstubAllEnvs();
Expand Down Expand Up @@ -30,4 +34,12 @@ describe("hasCloudPublicConfig", () => {

expect(hasCloudPublicConfig()).toBe(false);
});

it("reports the missing Clerk JWT template as structured configuration", () => {
vi.stubEnv("VITE_CLERK_JWT_TEMPLATE", "");

expect(() => resolveRelayClerkTokenOptions()).toThrowError(
new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" }),
);
});
});
14 changes: 13 additions & 1 deletion apps/web/src/cloud/publicConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { relayClerkTokenOptions } from "@t3tools/shared/relayAuth";
import { normalizeSecureRelayUrl } from "@t3tools/shared/relayUrl";
import * as Schema from "effect/Schema";

export class CloudPublicConfigMissingError extends Schema.TaggedErrorClass<CloudPublicConfigMissingError>()(
"CloudPublicConfigMissingError",
{
key: Schema.Literal("T3CODE_CLERK_JWT_TEMPLATE"),
},
) {
override get message(): string {
return `${this.key} is not configured.`;
}
}

export interface CloudPublicConfig {
readonly clerkPublishableKey: string | null;
Expand Down Expand Up @@ -65,7 +77,7 @@ export function hasCloudPublicConfig(): boolean {
export function resolveRelayClerkTokenOptions() {
const { clerkJwtTemplate } = resolveCloudPublicConfig();
if (!clerkJwtTemplate) {
throw new Error("T3CODE_CLERK_JWT_TEMPLATE is not configured.");
throw new CloudPublicConfigMissingError({ key: "T3CODE_CLERK_JWT_TEMPLATE" });
}
return relayClerkTokenOptions(clerkJwtTemplate);
}
Loading