Skip to content

Commit 59ffed3

Browse files
committed
fix: convert ws:// URLs to http:// before passing to fetch() in auth bootstrap
The fetch() API only supports http:// and https:// protocols. resolvePrimaryEnvironmentBootstrapUrl() returns ws:// URLs (from desktop bridge or VITE_WS_URL), which causes a TypeError when passed to fetch(). Add wsUrlToHttpUrl() helper that converts ws:/wss: protocols to http:/https: and apply it at all call sites that pass the resolved URL to fetch().
1 parent c28cc64 commit 59ffed3

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

apps/web/src/authBootstrap.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ describe("resolveInitialServerAuthGateState", () => {
8686

8787
expect(fetchMock).toHaveBeenCalledTimes(2);
8888
expect(fetchMock.mock.calls[0]?.[0]).toEqual(
89-
new URL("/api/auth/session", "ws://localhost:3773/"),
89+
new URL("/api/auth/session", "http://localhost:3773/"),
9090
);
9191
expect(fetchMock.mock.calls[1]?.[0]).toEqual(
92-
new URL("/api/auth/bootstrap", "ws://localhost:3773/"),
92+
new URL("/api/auth/bootstrap", "http://localhost:3773/"),
9393
);
9494
});
9595

apps/web/src/authBootstrap.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import type { AuthBootstrapInput, AuthBootstrapResult, AuthSessionState } from "
22

33
import { resolvePrimaryEnvironmentBootstrapUrl } from "./environmentBootstrap";
44

5+
function wsUrlToHttpUrl(url: string): string {
6+
const parsed = new URL(url);
7+
if (parsed.protocol === "ws:") parsed.protocol = "http:";
8+
else if (parsed.protocol === "wss:") parsed.protocol = "https:";
9+
return parsed.href;
10+
}
11+
512
export type ServerAuthGateState =
613
| { status: "authenticated" }
714
| {
@@ -80,7 +87,7 @@ async function exchangeBootstrapCredential(
8087
}
8188

8289
async function bootstrapServerAuth(): Promise<ServerAuthGateState> {
83-
const baseUrl = resolvePrimaryEnvironmentBootstrapUrl();
90+
const baseUrl = wsUrlToHttpUrl(resolvePrimaryEnvironmentBootstrapUrl());
8491
const bootstrapCredential = getBootstrapCredential();
8592
const currentSession = await fetchSessionState(baseUrl);
8693
if (currentSession.authenticated) {
@@ -112,7 +119,10 @@ export async function submitServerAuthCredential(credential: string): Promise<vo
112119
throw new Error("Enter a pairing token to continue.");
113120
}
114121

115-
await exchangeBootstrapCredential(resolvePrimaryEnvironmentBootstrapUrl(), trimmedCredential);
122+
await exchangeBootstrapCredential(
123+
wsUrlToHttpUrl(resolvePrimaryEnvironmentBootstrapUrl()),
124+
trimmedCredential,
125+
);
116126
stripPairingTokenFromUrl();
117127
}
118128

0 commit comments

Comments
 (0)