Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(web): show friendly error for invalid pairing token (#2222)
Saikrishna Ambeti8f50ca8e2c0e
diff --git a/apps/web/src/authBootstrap.test.ts b/apps/web/src/authBootstrap.test.tsindex b06c4248f..e6f08f147 100644--- a/apps/web/src/authBootstrap.test.ts+++ b/apps/web/src/authBootstrap.test.ts@@ -353,6 +353,34 @@ describe("resolveInitialServerAuthGateState", () => {expect(fetchMock).toHaveBeenCalledTimes(3);});+ it("surfaces a friendly error message when an invalid pairing token is submitted", async () => {+ const fetchMock = vi.fn<typeof fetch>().mockResolvedValueOnce(+ jsonResponse(+ {+ error: "Invalid bootstrap credential.",+ },+ {+ status: 401,+ },+ ),+ );+ vi.stubGlobal("fetch", fetchMock);++ const { submitServerAuthCredential } = await import("./environments/primary");++ await expect(submitServerAuthCredential("bad-token")).rejects.toThrow(+ "Invalid pairing token. Check the token and try again.",+ );+ expect(fetchMock).toHaveBeenCalledWith("http://localhost/api/auth/bootstrap", {+ body: JSON.stringify({ credential: "bad-token" }),+ credentials: "include",+ headers: {+ "content-type": "application/json",+ },+ method: "POST",+ });+ });+it("waits for the authenticated session to become observable after silent desktop bootstrap", async () => {vi.useFakeTimers();const fetchMock = vidiff --git a/apps/web/src/environments/primary/auth.ts b/apps/web/src/environments/primary/auth.tsindex 42eaa821c..93fcdd5fc 100644--- a/apps/web/src/environments/primary/auth.ts+++ b/apps/web/src/environments/primary/auth.ts@@ -110,6 +110,40 @@ async function readErrorMessage(response: Response, fallbackMessage: string): Prreturn text || fallbackMessage;}+const INVALID_BOOTSTRAP_CREDENTIAL_MESSAGES = new Set([+ "Invalid bootstrap credential.",+ "Unknown bootstrap credential.",+]);++function parseBootstrapErrorMessage(message: string): string {+ const trimmed = message.trim();+ if (trimmed.length === 0) {+ return "";+ }++ try {+ const parsed = JSON.parse(trimmed) as {+ error?: unknown;+ };+ if (typeof parsed.error === "string" && parsed.error.trim().length > 0) {+ return parsed.error.trim();+ }+ } catch {+ // Not JSON; fall back to plain text.+ }++ return trimmed;+}++function toFriendlyBootstrapErrorMessage(status: number, message: string): string {+ const parsedMessage = parseBootstrapErrorMessage(message);+ if (status === 401 && INVALID_BOOTSTRAP_CREDENTIAL_MESSAGES.has(parsedMessage)) {+ return "Invalid pairing token. Check the token and try again.";+ }++ return parsedMessage;+}+async function exchangeBootstrapCredential(credential: string): Promise<AuthBootstrapResult> {return retryTransientBootstrap(async () => {const payload: AuthBootstrapInput = { credential };@@ -123,7 +157,7 @@ async function exchangeBootstrapCredential(credential: string): Promise<AuthBoot});if (!response.ok) {- const message = await response.text();+ const message = toFriendlyBootstrapErrorMessage(response.status, await response.text());throw new BootstrapHttpError({message: message || `Failed to bootstrap auth session (${response.status}).`,status: response.status,