From 7ac582f80384b95789b88c3f216383ea0ff4ebaa Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:55:22 +0100 Subject: [PATCH] fix: compile the desktop trust path out of every other build, and fail a build that keeps it --- app/(main)/[locale]/login/page.tsx | 50 ++++++++++++----------- app/api/auth/totp-token-exchange/route.ts | 3 +- lib/__tests__/standalone-guard.test.ts | 7 ++++ lib/admin/jmap-servers.ts | 8 ++-- lib/desktop/__tests__/trust-flag.test.ts | 8 ++++ lib/desktop/types.ts | 5 ++- scripts/desktop-build-flag.mjs | 3 ++ scripts/standalone-guard.mjs | 9 ++-- 8 files changed, 60 insertions(+), 33 deletions(-) diff --git a/app/(main)/[locale]/login/page.tsx b/app/(main)/[locale]/login/page.tsx index d28ae4039..3ac336bd2 100644 --- a/app/(main)/[locale]/login/page.tsx +++ b/app/(main)/[locale]/login/page.tsx @@ -993,30 +993,34 @@ function LoginPageContent() { }; /** The desktop build: the server's own sign-in page in the system browser. */ + // Spelled out, not IS_DESKTOP_BUILD: only this form keeps the route out of other + // builds' bundles, which Lite's check on API strings relies on. const handleDesktopBrowserSignIn = async () => { - const target = jmapEndpoint.trim(); - if (!target) { - setDesktopNotice(tDesktop("server_needed")); - return; + if (process.env.NEXT_PUBLIC_BULWARK_DESKTOP === '1') { + const target = jmapEndpoint.trim(); + if (!target) { + setDesktopNotice(tDesktop("server_needed")); + return; + } + setDesktopNotice(null); + setDesktopWaiting(true); + const prefix = getPathPrefix(params.locale as string); + const outcome = await runDesktopBrowserSignIn({ + serverUrl: target, + callbackPath: `${prefix}/${params.locale}/auth/callback`, + slot: useAccountStore.getState().getNextCookieSlot(), + remember: persistProviderSession, + addAccount: isAddAccountMode, + }); + if (outcome.kind === "callback") { + window.location.href = outcome.callbackUrl; + return; + } + setDesktopWaiting(false); + if (outcome.kind === "unavailable") setDesktopNotice(tDesktop("browser_unavailable")); + else if (outcome.kind === "declined") setDesktopNotice(tDesktop("server_declined")); + else if (outcome.kind === "failed") setDesktopNotice(tDesktop("browser_failed")); } - setDesktopNotice(null); - setDesktopWaiting(true); - const prefix = getPathPrefix(params.locale as string); - const outcome = await runDesktopBrowserSignIn({ - serverUrl: target, - callbackPath: `${prefix}/${params.locale}/auth/callback`, - slot: useAccountStore.getState().getNextCookieSlot(), - remember: persistProviderSession, - addAccount: isAddAccountMode, - }); - if (outcome.kind === "callback") { - window.location.href = outcome.callbackUrl; - return; - } - setDesktopWaiting(false); - if (outcome.kind === "unavailable") setDesktopNotice(tDesktop("browser_unavailable")); - else if (outcome.kind === "declined") setDesktopNotice(tDesktop("server_declined")); - else if (outcome.kind === "failed") setDesktopNotice(tDesktop("browser_failed")); }; const handleSubmit = async (e: React.FormEvent) => { @@ -1858,7 +1862,7 @@ function LoginPageContent() { )} - {IS_DESKTOP_BUILD && !hasServerList && browserSignInAvailable() && ( + {process.env.NEXT_PUBLIC_BULWARK_DESKTOP === "1" && !hasServerList && browserSignInAvailable() && (