Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(desktop): offer "switch to Localhost" when login hits a dead backend

Andy Paviaafc50865b669
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.json
index 961298c21..18c7e81bc 100644
--- a/desktop-app/package-lock.json
+++ b/desktop-app/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "evenfire",
- "version": "0.1.333",
+ "version": "0.1.334",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "evenfire",
- "version": "0.1.333",
+ "version": "0.1.334",
"license": "MPL-2.0",
"dependencies": {
"@clerum/desktop-app-links": "file:../packages/desktop-app-links",
diff --git a/desktop-app/package.json b/desktop-app/package.json
index f95c2947a..734fef64c 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -1,7 +1,7 @@
{
"name": "evenfire",
"productName": "Evenfire",
- "version": "0.1.333",
+ "version": "0.1.334",
"private": true,
"license": "MPL-2.0",
"description": "Evenfire desktop client for secure agent and workflow access",
diff --git a/desktop-app/src/__tests__/appService.diagnoseLoginBackend.test.ts b/desktop-app/src/__tests__/appService.diagnoseLoginBackend.test.ts
new file mode 100644
index 000000000..386ae7ec9
--- /dev/null
+++ b/desktop-app/src/__tests__/appService.diagnoseLoginBackend.test.ts
@@ -0,0 +1,117 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+
+// config.ts touches the Electron `app` at module load; provide a minimal mock
+// with a NON-packaged, ready app so the env-var runtime-config path is active
+// (envRuntimeConfigured requires !app.isPackaged).
+vi.mock('electron', () => ({
+ app: {
+ getPath: vi.fn(() => '/tmp/evenfire-test-userdata'),
+ isPackaged: false,
+ isReady: vi.fn(() => true),
+ setName: vi.fn(),
+ setPath: vi.fn(),
+ getName: vi.fn(() => 'Evenfire'),
+ },
+}))
+
+// The chat store binds to the real filesystem; stub it so importing appService
+// never touches Electron userData.
+vi.mock('../chatStoreBinding.js', () => ({
+ bindChatStoreForUser: vi.fn(),
+ unbindChatStore: vi.fn(),
+}))
+
+const LOCALHOST_EXTERNAL = 'http://127.0.0.1:8091'
+const LOCALHOST_RPC = 'http://127.0.0.1:8094'
+const REMOTE_EXTERNAL = 'https://api.example.com'
+const REMOTE_RPC = 'https://rpc.example.com'
+
+type HealthByUrl = (baseUrl: string) => Promise<{ status: string }>
+
+async function makeService(healthAt: HealthByUrl) {
+ vi.resetModules()
+ const { AppService } = await import('../appService.js')
+ const service = new AppService() as unknown as {
+ authClient: { healthAt: ReturnType<typeof vi.fn> }
+ diagnoseLoginBackend: () => Promise<unknown>
+ }
+ service.authClient = { healthAt: vi.fn(healthAt) } as never
+ return service
+}
+
+/** A probe that answers only for URLs whose host appears in `reachableHosts`. */
+function healthReachableFor(...reachableHosts: string[]): HealthByUrl {
+ return async (baseUrl: string) => {
+ if (reachableHosts.some(host => baseUrl.includes(host))) return { status: 'ok' }
+ throw new Error('ECONNREFUSED')
+ }
+}
+
+describe('AppService.diagnoseLoginBackend', () => {
+ const saved = {
+ external: process.env.EXTERNAL_REST_API_BASE_URL,
+ rpc: process.env.RPC_PROXY_BASE_URL,
+ profileUi: process.env.PROFILE_UI_BASE_URL,
+ }
+
+ beforeEach(() => {
+ delete process.env.PROFILE_UI_BASE_URL
+ })
+
+ afterEach(() => {
+ for (const [key, value] of [
+ ['EXTERNAL_REST_API_BASE_URL', saved.external],
+ ['RPC_PROXY_BASE_URL', saved.rpc],
+ ['PROFILE_UI_BASE_URL', saved.profileUi],
+ ] as const) {
+ if (value === undefined) delete process.env[key]
+ else process.env[key] = value
+ }
+ vi.resetModules()
+ })
+
+ it('offers a switch to Localhost when the active backend is unreachable and localhost is up', async () => {
+ process.env.EXTERNAL_REST_API_BASE_URL = REMOTE_EXTERNAL
+ process.env.RPC_PROXY_BASE_URL = REMOTE_RPC
+
+ const service = await makeService(healthReachableFor('127.0.0.1'))
+ const hint = (await service.diagnoseLoginBackend()) as {
+ targetOptionId: string
+ targetLabel: string
+ activeLabel: string
+ } | null
+
+ expect(hint).not.toBeNull()
+ expect(hint?.targetOptionId).toBe('__localhost__')
+ expect(hint?.targetLabel).toBe('Localhost')
+ expect(typeof hint?.activeLabel).toBe('string')
+ expect(hint?.activeLabel.length).toBeGreaterThan(0)
+ })
+
+ it('stays silent when the active backend is reachable (a healthy backend is not a wrong-server)', async () => {
+ process.env.EXTERNAL_REST_API_BASE_URL = REMOTE_EXTERNAL
+ process.env.RPC_PROXY_BASE_URL = REMOTE_RPC
+
+ // Both the remote and localhost answer — the failure was not "wrong server".
+ const service = await makeService(healthReachableFor('api.example.com', '127.0.0.1'))
+ expect(await service.diagnoseLoginBackend()).toBeNull()
+ })
+
+ it('stays silent when localhost is not reachable (nothing to switch to)', async () => {
+ process.env.EXTERNAL_REST_API_BASE_URL = REMOTE_EXTERNAL
+ process.env.RPC_PROXY_BASE_URL = REMOTE_RPC
+
+ // Nothing answers, including localhost.
+ const service = await makeService(healthReachableFor())
+ expect(await service.diagnoseLoginBackend()).toBeNull()
+ })
+
+ it('stays silent and never probes when the app is already on localhost', async () => {
+ process.env.EXTERNAL_REST_API_BASE_URL = LOCALHOST_EXTERNAL
+ process.env.RPC_PROXY_BASE_URL = LOCALHOST_RPC
+
+ const service = await makeService(healthReachableFor('127.0.0.1'))
+ expect(await service.diagnoseLoginBackend()).toBeNull()
+ expect(service.authClient.healthAt).not.toHaveBeenCalled()
+ })
+})
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index 19d3d64e3..c9abb48e1 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -42,6 +42,7 @@ import {
HostModelsResult,
HostRuntimeStatus,
HostStatusStreamEvent,
+ LoginBackendHint,
PasswordLoginResult,
PendingApprovalLite,
PendingWorkflowApproval,
@@ -72,6 +73,11 @@ import {
// bounded-and-once for that operation (issue #791). control-api intersects the
// requested scopes against the caller's grants before issuance, so requesting
// the wake scope never widens a caller who was not granted it.
+// Upper bound for a single backend-reachability probe used by
+// `diagnoseLoginBackend`. Kept short so a post-login-failure diagnosis never
+// makes the failure feel slower than it already did.
+const BACKEND_PROBE_TIMEOUT_MS = 1500
+
const HOST_WAKE_SCOPE: RpcScope = 'host:wake:write'
function normalizeExplicitProfileUiBaseUrl(rawValue: string): string | null {
@@ -820,6 +826,59 @@ export class AppService {
return this.completePasswordLogin(normalizedEmail, password)
}
+ /**
+ * After a login failure, decide whether to offer a one-click "switch to
+ * Localhost and retry". Returns a hint ONLY when all hold:
+ * - the active runtime profile is NOT already localhost,
+ * - a local Evenfire external-rest-api answers `/health`, and
+ * - the active backend does NOT answer `/health` (i.e. the failure looks
+ * like "pointed at the wrong/dead backend", not a bad password against a
+ * healthy one).
+ * Self-contained (reads current runtime state + probes reachability), so it
+ * never second-guesses a reachable backend and needs no detail from the
+ * thrown login error. Best-effort and time-bounded — a slow network yields
+ * `null`, never a slower login.
+ */
+ async diagnoseLoginBackend(): Promise<LoginBackendHint | null> {
+ hydrateDesktopRuntimeConfig()
+ const state = getDesktopRuntimeConfigState()
+ if (state.isLocalhost) return null
+
+ const localhostOption = state.options.find(option => option.source === 'localhost')
+ if (!localhostOption?.externalRestApiBaseUrl) return null
+
+ const activeOption = state.options.find(option => option.id === state.activeOptionId) ?? null
+ const activeBaseUrl = activeOption?.externalRestApiBaseUrl || config.externalRestApiBaseUrl
+ // Nothing to switch to if we're already pointed at the localhost origin.
+ if (activeBaseUrl === localhostOption.externalRestApiBaseUrl) return null
+
+ const [localhostReachable, activeReachable] = await Promise.all([
+ this.probeBackendHealthy(localhostOption.externalRestApiBaseUrl),
+ this.probeBackendHealthy(activeBaseUrl),
+ ])
+ if (!localhostReachable || activeReachable) return null
+
+ return {
+ targetOptionId: localhostOption.id,
+ targetLabel: localhostOption.label,
+ activeLabel: activeOption?.label || config.appName || activeBaseUrl,
+ }
+ }
+
+ /** True iff `<baseUrl>/health` returns `{ status: 'ok' }` within the probe bound. */
+ private async probeBackendHealthy(baseUrl: string): Promise<boolean> {
+ if (!baseUrl?.trim()) return false
+ try {
+ const result = await this.authClient.healthAt(
+ baseUrl,
+ AbortSignal.timeout(BACKEND_PROBE_TIMEOUT_MS)
+ )
+ return result?.status === 'ok'
+ } catch {
+ return false
+ }
+ }
+
private async resolveRuntimeConfigIfNeeded(): Promise<void> {
hydrateDesktopRuntimeConfig()
if (!isDesktopRuntimeConfigured()) return
diff --git a/desktop-app/src/authClient.ts b/desktop-app/src/authClient.ts
index e406b4b79..74901a6c3 100644
--- a/desktop-app/src/authClient.ts
+++ b/desktop-app/src/authClient.ts
@@ -276,6 +276,18 @@ export class AuthClient {
return requestJson<{ status: string }>('GET', url('/health'))
}
+ /**
+ * Health check against an EXPLICIT external-rest-api base URL rather than the
+ * active `config` one. Used to probe a candidate backend (e.g. localhost)
+ * without mutating the active runtime config. Pass a short-lived `signal`
+ * (e.g. `AbortSignal.timeout(...)`) to keep the probe snappy — the app-wide
+ * timeout still applies as an upper bound via `withTimeout`.
+ */
+ async healthAt(baseUrl: string, signal?: AbortSignal): Promise<{ status: string }> {
+ const normalized = baseUrl.replace(/\/+$/, '')
+ return requestJson<{ status: string }>('GET', `${normalized}/health`, { signal })
+ }
+
async getDesktopEnvironment(): Promise<DesktopEnvironmentDiscovery> {
return requestJson<DesktopEnvironmentDiscovery>('GET', url('/api/v1/desktop/environment'))
}
diff --git a/desktop-app/src/ipc.ts b/desktop-app/src/ipc.ts
index 9dfee7e54..a07aa47cb 100644
--- a/desktop-app/src/ipc.ts
+++ b/desktop-app/src/ipc.ts
@@ -176,6 +176,10 @@ export function registerIpcHandlers(service: AppService): void {
)
}
)
+ ipcMain.handle('auth:diagnoseLoginBackend', async event => {
+ assertTrustedSender(event)
+ return service.diagnoseLoginBackend()
+ })
ipcMain.handle('auth:startDesktopSetup', async (event, payload: { email: string }) => {
assertTrustedSender(event)
return service.startDesktopSetup(sanitizeString(payload?.email).toLowerCase())
diff --git a/desktop-app/src/preload.ts b/desktop-app/src/preload.ts
index 48ff35fab..434b6567a 100644
--- a/desktop-app/src/preload.ts
+++ b/desktop-app/src/preload.ts
@@ -23,6 +23,7 @@ const clerum = Object.freeze({
googleLogin: (idToken: string) => ipcRenderer.invoke('auth:googleLogin', { idToken }),
passwordLogin: (email: string, password: string) =>
ipcRenderer.invoke('auth:passwordLogin', { email, password }),
+ diagnoseLoginBackend: () => ipcRenderer.invoke('auth:diagnoseLoginBackend'),
startDesktopSetup: (email: string) => ipcRenderer.invoke('auth:startDesktopSetup', { email }),
openForgotPassword: (email?: string) =>
ipcRenderer.invoke('auth:openForgotPassword', { email }),
diff --git a/desktop-app/src/renderer.d.ts b/desktop-app/src/renderer.d.ts
index 2301effcf..bab61efe6 100644
--- a/desktop-app/src/renderer.d.ts
+++ b/desktop-app/src/renderer.d.ts
@@ -18,6 +18,7 @@ import {
HostModelsResult,
HostRuntimeStatus,
HostStatusStreamEvent,
+ LoginBackendHint,
MessageToolStep,
PasswordLoginResult,
PendingApprovalLite,
@@ -59,6 +60,7 @@ declare global {
deleteRuntimeConfig: (optionId: string) => Promise<DesktopRuntimeConfigState>
googleLogin: (idToken: string) => Promise<SessionState>
passwordLogin: (email: string, password: string) => Promise<PasswordLoginResult>
+ diagnoseLoginBackend: () => Promise<LoginBackendHint | null>
startDesktopSetup: (email: string) => Promise<{ profileUiUrl: string; appName: string }>
openForgotPassword: (email?: string) => Promise<{ profileUiUrl: string }>
openProfileSettings: (
diff --git a/desktop-app/src/types.ts b/desktop-app/src/types.ts
index e34c2ca63..fb8410115 100644
--- a/desktop-app/src/types.ts
+++ b/desktop-app/src/types.ts
@@ -527,6 +527,22 @@ export type SessionState = {
export type PasswordLoginResult = SessionState
+/**
+ * Actionable diagnosis returned after a login failure when the app is pointed at
+ * a backend that isn't answering but a local Evenfire (minikube) IS reachable.
+ * Surfaced as a one-click "switch to Localhost and retry" affordance so a
+ * connection failure against the wrong runtime profile stops reading as a bare
+ * "login failed". Computed by `AppService.diagnoseLoginBackend`.
+ */
+export type LoginBackendHint = {
+ /** Runtime-config option to switch to (the localhost option's id). */
+ targetOptionId: string
+ /** Human label for the switch target, e.g. "Localhost". */
+ targetLabel: string
+ /** Human label for the backend the user is currently pointed at. */
+ activeLabel: string
+}
+
export type InvitationPreview = {
id: string
teamId: string
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsx
index 5b9c335ee..93bd15640 100644
--- a/desktop-app/ui/src/App.tsx
+++ b/desktop-app/ui/src/App.tsx
@@ -803,6 +803,7 @@ export function App() {
runtimeConfigState: vm.runtimeConfigState,
desktopReleaseStatus: vm.desktopReleaseStatus,
pendingDesktopEnvironmentSetup: vm.pendingDesktopEnvironmentSetup,
+ backendSwitchHint: vm.backendSwitchHint,
runtimeConfigMissing: vm.runtimeConfigMissing,
showRuntimeConfigSelector: vm.showRuntimeConfigSelector,
dependencyHealth: vm.dependencyHealth,
@@ -819,6 +820,7 @@ export function App() {
setStatus: vm.setStatus,
loadSession: vm.loadSession,
handlePasswordLogin: vm.handlePasswordLogin,
+ handleSwitchLoginBackend: vm.handleSwitchLoginBackend,
handleStartDesktopSetup: vm.handleStartDesktopSetup,
handleCompleteDesktopSetup: vm.handleCompleteDesktopSetup,
handleSaveRuntimeConfig: vm.handleSaveRuntimeConfig,
@@ -832,6 +834,7 @@ export function App() {
}),
[
vm.authTransitioning,
+ vm.backendSwitchHint,
vm.booting,
vm.busy,
vm.dependencyHealth,
@@ -848,6 +851,7 @@ export function App() {
vm.handleLogout,
vm.handleOpenDesktopRelease,
vm.handlePasswordLogin,
+ vm.handleSwitchLoginBackend,
vm.handleSaveRuntimeConfig,
vm.handleSelectRuntimeConfig,
vm.handleStartDesktopSetup,
diff --git a/desktop-app/ui/src/contexts/AuthContext.types.ts b/desktop-app/ui/src/contexts/AuthContext.types.ts
index c998eac1e..8ee1f427b 100644
--- a/desktop-app/ui/src/contexts/AuthContext.types.ts
+++ b/desktop-app/ui/src/contexts/AuthContext.types.ts
@@ -3,6 +3,7 @@ import type {
DesktopReleaseStatus,
DesktopRuntimeConfig,
DesktopRuntimeConfigState,
+ LoginBackendHint,
SessionMe,
} from '../../../src/types'
import type { Tone } from '../uiTypes'
@@ -26,6 +27,7 @@ export interface AuthContextValue {
runtimeConfigState: DesktopRuntimeConfigState | null
desktopReleaseStatus: DesktopReleaseStatus | null
pendingDesktopEnvironmentSetup: DesktopRuntimeConfig | null
+ backendSwitchHint: LoginBackendHint | null
runtimeConfigMissing: boolean
showRuntimeConfigSelector: boolean
dependencyHealth: DependencyHealth | null
@@ -47,6 +49,7 @@ export interface AuthContextValue {
) => void
loadSession: (options?: { preserveNav?: boolean }) => Promise<void>
handlePasswordLogin: () => Promise<void>
+ handleSwitchLoginBackend: () => Promise<void>
handleStartDesktopSetup: () => Promise<void>
handleCompleteDesktopSetup: () => Promise<void>
handleSaveRuntimeConfig: (
diff --git a/desktop-app/ui/src/hooks/domain/useAuthController.ts b/desktop-app/ui/src/hooks/domain/useAuthController.ts
index 76d71a2b0..d3cfcdf0e 100644
--- a/desktop-app/ui/src/hooks/domain/useAuthController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAuthController.ts
@@ -6,6 +6,7 @@ import type {
DesktopReleaseStatus,
DesktopRuntimeConfig,
DesktopRuntimeConfigState,
+ LoginBackendHint,
SessionMe,
} from '../../../../src/types'
import type { Tone } from '../../uiTypes'
@@ -59,6 +60,7 @@ export function useAuthController({ setStatus, onSessionNeedsLoad }: UseAuthCont
const [desktopReleaseStatus, setDesktopReleaseStatus] = useState<DesktopReleaseStatus | null>(
null
)
+ const [backendSwitchHint, setBackendSwitchHint] = useState<LoginBackendHint | null>(null)
const [desktopEnvironmentSetupComplete, setDesktopEnvironmentSetupComplete] = useState(false)
const [pendingDesktopEnvironmentSetup, setPendingDesktopEnvironmentSetup] =
useState<DesktopRuntimeConfig | null>(null)
@@ -169,17 +171,20 @@ export function useAuthController({ setStatus, onSessionNeedsLoad }: UseAuthCont
try {
setBusy(true)
setAuthTransitioning(true)
+ setBackendSwitchHint(null)
const normalizedEmail = email.trim().toLowerCase()
if (!normalizedEmail || !password) throw new Error('email and password are required')
await window.clerum.auth.passwordLogin(normalizedEmail, password)
setStatus('Signed in.', 'success')
await onSessionNeedsLoad({ preserveNav: true })
} catch (error) {
+ const invitationExpired = isInvitationExpiredError(error)
+ const missingInvitationConfig = isMissingInvitationConfigError(error)
const unauthorized = isUnauthorizedError(error)
setStatus(
- isInvitationExpiredError(error)
+ invitationExpired
? 'Invitation expired.'
- : isMissingInvitationConfigError(error)
+ : missingInvitationConfig
? 'You must be invited to be part of a team.'
: unauthorized
? 'Email or password is incorrect.'
@@ -188,12 +193,38 @@ export function useAuthController({ setStatus, onSessionNeedsLoad }: UseAuthCont
undefined,
unauthorized ? { toastDurationMs: DEFAULT_TOAST_DURATION_MS } : undefined
)
+ // A generic (non-401, non-invitation) failure is the signature of a login
+ // aimed at a backend that isn't answering — most often the app is on a
+ // saved profile while a local minikube cluster is what's actually up.
+ // Only then do we probe for a reachable localhost and, if found, offer a
+ // one-click switch. A clean 401 means the backend answered, so it's a
+ // password problem, not a wrong-server problem — no switch offered.
+ if (!invitationExpired && !missingInvitationConfig && !unauthorized) {
+ try {
+ const hint =
+ typeof window.clerum.auth.diagnoseLoginBackend === 'function'
+ ? await window.clerum.auth.diagnoseLoginBackend()
+ : null
+ setBackendSwitchHint(hint)
+ } catch {
+ setBackendSwitchHint(null)
+ }
+ }
} finally {
setAuthTransitioning(false)
setBusy(false)
}
}
+ const handleSwitchLoginBackend = async () => {
+ const hint = backendSwitchHint
+ if (!hint) return
+ setBackendSwitchHint(null)
+ const state = await handleSelectRuntimeConfig(hint.targetOptionId)
+ if (!state) return
+ await handlePasswordLogin()
+ }
+
const handleStartDesktopSetup = async () => {
try {
setBusy(true)
@@ -299,6 +330,7 @@ export function useAuthController({ setStatus, onSessionNeedsLoad }: UseAuthCont
): Promise<DesktopRuntimeConfigState | null> => {
try {
setBusy(true)
+ setBackendSwitchHint(null)
const state = await window.clerum.auth.selectRuntimeConfig(optionId)
// Switching environment (pre-login) must not carry another env's cached
// queries forward (spec §5.2 P1). The env is bound to login (D4: no switch
@@ -406,6 +438,7 @@ export function useAuthController({ setStatus, onSessionNeedsLoad }: UseAuthCont
desktopReleaseStatus,
desktopEnvironmentSetupComplete,
pendingDesktopEnvironmentSetup,
+ backendSwitchHint,
runtimeConfigMissing,
showRuntimeConfigSelector,
hasDependencyOutage,
@@ -426,8 +459,10 @@ export function useAuthController({ setStatus, onSessionNeedsLoad }: UseAuthCont
setDesktopReleaseStatus,
setDesktopEnvironmentSetupComplete,
setPendingDesktopEnvironmentSetup,
+ setBackendSwitchHint,
refreshRuntimeConfigState,
handlePasswordLogin,
+ handleSwitchLoginBackend,
handleStartDesktopSetup,
handleCompleteDesktopSetup,
handleSaveRuntimeConfig,
diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.ts
index 37b3b7aa1..b64663bdd 100644
--- a/desktop-app/ui/src/hooks/useAppController.ts
+++ b/desktop-app/ui/src/hooks/useAppController.ts
@@ -1060,6 +1060,7 @@ export function useAppController() {
desktopReleaseStatus: auth.desktopReleaseStatus,
desktopEnvironmentSetupComplete: auth.desktopEnvironmentSetupComplete,
pendingDesktopEnvironmentSetup: auth.pendingDesktopEnvironmentSetup,
+ backendSwitchHint: auth.backendSwitchHint,
showRuntimeConfigSelector: auth.showRuntimeConfigSelector,
dependencyHealth: auth.dependencyHealth,
hasDependencyOutage: auth.hasDependencyOutage,
@@ -1074,6 +1075,7 @@ export function useAppController() {
setStatus: fullSetStatus,
loadSession,
handlePasswordLogin: auth.handlePasswordLogin,
+ handleSwitchLoginBackend: auth.handleSwitchLoginBackend,
handleStartDesktopSetup: auth.handleStartDesktopSetup,
handleCompleteDesktopSetup: auth.handleCompleteDesktopSetup,
handleSaveRuntimeConfig: auth.handleSaveRuntimeConfig,
diff --git a/desktop-app/ui/src/pages/AuthPage/index.tsx b/desktop-app/ui/src/pages/AuthPage/index.tsx
index 4810036c6..4fd38bb96 100644
--- a/desktop-app/ui/src/pages/AuthPage/index.tsx
+++ b/desktop-app/ui/src/pages/AuthPage/index.tsx
@@ -1,7 +1,7 @@
import type { FormEvent } from 'react'
import { useEffect, useRef, useState } from 'react'
import { useAuthContext } from '@contexts/AuthContext'
-import { Button, Field, IconButton, MenuItem, TextInput } from '@components/Common'
+import { Button, Field, IconButton, MenuItem, StatusBanner, TextInput } from '@components/Common'
import { ConfirmDialog } from '@components/ConfirmDialog'
import {
LOCALHOST_RUNTIME_CONFIG_OPTION_ID,
@@ -21,12 +21,14 @@ export function AuthPage() {
authTransitioning,
runtimeConfigState,
runtimeConfigMissing,
+ backendSwitchHint,
setEmail,
setPassword,
setRuntimeConfigSetupName,
setRuntimeConfigSetupExternalRestApiBaseUrl,
setStatus,
handlePasswordLogin,
+ handleSwitchLoginBackend,
handleStartDesktopSetup,
handleSaveRuntimeConfig,
handleDeleteRuntimeConfig,
@@ -239,6 +241,27 @@ export function AuthPage() {
>
Forgot password
</button>
+ {backendSwitchHint ? (
+ <StatusBanner tone="warn">
+ <span className="auth-backend-hint">
+ <span>
+ Couldn’t reach <strong>{backendSwitchHint.activeLabel}</strong>. A local
+ Evenfire looks like it’s running — switch to{' '}
+ <strong>{backendSwitchHint.targetLabel}</strong> and retry?
+ </span>
+ <Button
+ type="button"
+ size="sm"
+ variant="soft"
+ block
+ disabled={busy}
+ onClick={() => void handleSwitchLoginBackend()}
+ >
+ {`Switch to ${backendSwitchHint.targetLabel} & retry`}
+ </Button>
+ </span>
+ </StatusBanner>
+ ) : null}
</form>
) : null}
diff --git a/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsx b/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsx
index 643781d9f..f209728ce 100644
--- a/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/AuthPage.test.tsx
@@ -38,6 +38,7 @@ const makeAuthValue = (overrides: Partial<AuthContextValue> = {}): AuthContextVa
},
desktopReleaseStatus: null,
pendingDesktopEnvironmentSetup: null,
+ backendSwitchHint: null,
runtimeConfigMissing: false,
showRuntimeConfigSelector: false,
dependencyHealth: null,
@@ -54,6 +55,7 @@ const makeAuthValue = (overrides: Partial<AuthContextValue> = {}): AuthContextVa
setStatus: vi.fn(),
loadSession: vi.fn(),
handlePasswordLogin: vi.fn(),
+ handleSwitchLoginBackend: vi.fn(),
handleStartDesktopSetup: vi.fn(),
handleCompleteDesktopSetup: vi.fn(),
handleSaveRuntimeConfig: vi.fn(),
@@ -157,4 +159,31 @@ describe('AuthPage', () => {
expect(handleSelectRuntimeConfig).toHaveBeenCalledWith(LOCALHOST_RUNTIME_CONFIG_OPTION_ID)
})
+
+ it('offers a switch-and-retry action when a backend-mismatch hint is present', async () => {
+ const user = userEvent.setup()
+ const handleSwitchLoginBackend = vi.fn()
+
+ renderAuthPage({
+ backendSwitchHint: {
+ targetOptionId: LOCALHOST_RUNTIME_CONFIG_OPTION_ID,
+ targetLabel: 'Localhost',
+ activeLabel: 'Production',
+ },
+ handleSwitchLoginBackend,
+ })
+
+ const switchButton = screen.getByRole('button', { name: /Switch to Localhost & retry/ })
+ expect(switchButton).toBeTruthy()
+
+ await user.click(switchButton)
+
+ expect(handleSwitchLoginBackend).toHaveBeenCalledTimes(1)
+ })
+
+ it('shows no switch affordance when there is no backend-mismatch hint', () => {
+ renderAuthPage({ backendSwitchHint: null })
+
+ expect(screen.queryByRole('button', { name: /Switch to .* & retry/ })).toBeNull()
+ })
})
diff --git a/desktop-app/ui/src/pages/__tests__/ContextDetailsPage.test.tsx b/desktop-app/ui/src/pages/__tests__/ContextDetailsPage.test.tsx
index a505941c3..f3d18f6d4 100644
--- a/desktop-app/ui/src/pages/__tests__/ContextDetailsPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/ContextDetailsPage.test.tsx
@@ -90,6 +90,7 @@ const makeAuthValue = (overrides: Partial<AuthContextValue> = {}): AuthContextVa
runtimeConfigState: null,
desktopReleaseStatus: null,
pendingDesktopEnvironmentSetup: null,
+ backendSwitchHint: null,
runtimeConfigMissing: false,
showRuntimeConfigSelector: false,
dependencyHealth: null,
@@ -106,6 +107,7 @@ const makeAuthValue = (overrides: Partial<AuthContextValue> = {}): AuthContextVa
setStatus: vi.fn(),
loadSession: vi.fn(),
handlePasswordLogin: vi.fn(),
+ handleSwitchLoginBackend: vi.fn(),
handleStartDesktopSetup: vi.fn(),
handleCompleteDesktopSetup: vi.fn(),
handleSaveRuntimeConfig: vi.fn(),
diff --git a/desktop-app/ui/src/pages/__tests__/TeamsPage.test.tsx b/desktop-app/ui/src/pages/__tests__/TeamsPage.test.tsx
index c58de0619..4c4801be6 100644
--- a/desktop-app/ui/src/pages/__tests__/TeamsPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/TeamsPage.test.tsx
@@ -66,6 +66,7 @@ const makeAuthValue = (overrides: Partial<AuthContextValue> = {}): AuthContextVa
runtimeConfigState: null,
desktopReleaseStatus: null,
pendingDesktopEnvironmentSetup: null,
+ backendSwitchHint: null,
runtimeConfigMissing: false,
showRuntimeConfigSelector: false,
dependencyHealth: null,
@@ -82,6 +83,7 @@ const makeAuthValue = (overrides: Partial<AuthContextValue> = {}): AuthContextVa
setStatus: vi.fn(),
loadSession: vi.fn(),
handlePasswordLogin: vi.fn(),
+ handleSwitchLoginBackend: vi.fn(),
handleStartDesktopSetup: vi.fn(),
handleCompleteDesktopSetup: vi.fn(),
handleSaveRuntimeConfig: vi.fn(),
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 586dc9269..f0c6e18f2 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -10057,6 +10057,13 @@ button.page-breadcrumb-link--plain-action:hover:enabled {
margin-top: 2px;
}
+.auth-backend-hint {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-2);
+ align-items: stretch;
+}
+
.auth-button-loading {
display: inline-flex;
align-items: center;