Skip to content

Commit e59876a

Browse files
committed
fix(env): normalize URLs before comparing to avoid spurious mismatch warnings
Use new URL().href to normalize both the override and profile URL before comparing, so trailing slashes and host-case differences don't produce false positives. Falls back to raw string comparison when either URL is malformed. Also pin the test to a concrete literal ("https://api.clerk.com") instead of the self-referencing getPlapiBaseUrl() call, and strengthen the positive warning case by asserting the override host appears in the message.
1 parent 627fd6b commit e59876a

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

packages/cli-core/src/lib/environment.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, describe, beforeEach, afterEach } from "bun:test";
2-
import { getPlapiBaseUrl, warnIfPlatformApiUrlOverride } from "./environment.ts";
2+
import { warnIfPlatformApiUrlOverride } from "./environment.ts";
33
import { setMode } from "../mode.ts";
44
import { useCaptureLog } from "../test/lib/stubs.ts";
55

@@ -23,6 +23,7 @@ describe("warnIfPlatformApiUrlOverride", () => {
2323
warnIfPlatformApiUrlOverride();
2424
expect(captured.err).toContain("CLERK_PLATFORM_API_URL");
2525
expect(captured.err).toContain("production");
26+
expect(captured.err).toContain("api.staging.example.com");
2627
});
2728

2829
test("does not warn when no override is set", () => {
@@ -31,8 +32,7 @@ describe("warnIfPlatformApiUrlOverride", () => {
3132
});
3233

3334
test("does not warn when the override equals the active env URL", () => {
34-
const profileUrl = getPlapiBaseUrl(); // no override set → active env URL
35-
process.env.CLERK_PLATFORM_API_URL = profileUrl;
35+
process.env.CLERK_PLATFORM_API_URL = "https://api.clerk.com";
3636
warnIfPlatformApiUrlOverride();
3737
expect(captured.err).not.toContain("CLERK_PLATFORM_API_URL");
3838
});

packages/cli-core/src/lib/environment.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ export function warnIfPlatformApiUrlOverride(): void {
152152
const override = process.env.CLERK_PLATFORM_API_URL;
153153
if (!override) return;
154154
const envName = getCurrentEnvName();
155-
if (override === getCurrentEnv().platformApiUrl) return;
155+
const normalize = (u: string) => {
156+
try {
157+
return new URL(u).href;
158+
} catch {
159+
return u;
160+
}
161+
};
162+
if (normalize(override) === normalize(getCurrentEnv().platformApiUrl)) return;
156163
log.warn(
157164
`CLERK_PLATFORM_API_URL is routing requests to ${override}, but credentials stay keyed to the "${envName}" environment — the "${envName}" token will be sent to that host.`,
158165
);

0 commit comments

Comments
 (0)