fix(desktop): stop forcing login window on business API 401
Desktop Client Build / Resolve Build Metadata (push) Successful in 29s
Frontend CI / Frontend (push) Successful in 4m48s
Desktop Client Build / Build Desktop Client (push) Successful in 26m5s
Desktop Client Build / Publish Client Artifacts to NAS (push) Successful in 42s

Business calls (heartbeat, account sync, lease/pull/resume tasks,
preempt monitoring lease) used to short-circuit any 401 into
handleAuthExpired, which tore down the runtime and switched the
window to login. That stole the screen on transient or per-request
auth glitches and conflicted with the renderer-side proactive token
renewal.

Now business 401s fall through to the existing warn/danger activity
log paths and runtime keeps running. The login redirect is owned
solely by the renderer's renewAuthenticatedSession → on refresh /
rotate failure → forceLogoutAfterRenewFailure path. Server-side
revocation via error code 40991 is unaffected.

Removed the now-orphan plumbing: handleAuthExpired,
isApiClientError helper, emitRuntimeAuthExpired /
onRuntimeAuthExpired events, and forceLoginWindowForAuthExpired
listener registration.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-08 18:55:10 +08:00
parent e54efdacee
commit 94c6b5d5a5
3 changed files with 2 additions and 102 deletions
+1 -13
View File
@@ -48,7 +48,7 @@ import {
syncRuntimeSession,
unbindRuntimeAccount,
} from './runtime-controller'
import { onRuntimeAuthExpired, onRuntimeInvalidated } from './runtime-events'
import { onRuntimeInvalidated } from './runtime-events'
import { createRuntimeAccountSnapshot, createRuntimeSnapshot } from './runtime-snapshot'
import { initScheduler } from './scheduler'
import { initSessionRegistry } from './session-registry'
@@ -524,13 +524,6 @@ function queueWindowModeSwitch(
return nextSwitch
}
async function forceLoginWindowForAuthExpired(message: string): Promise<void> {
console.warn('[desktop-main] runtime auth expired; switching to login window', { message })
syncRuntimeSession(null)
await clearRendererDesktopSessions()
await queueWindowModeSwitch('login', { source: 'logout', animate: true }, currentMainWindow())
}
async function openSettingsWindow(): Promise<void> {
const window = await ensureSettingsWindow()
const parent = settingsWindowParent()
@@ -1006,11 +999,6 @@ if (!hasSingleInstanceLock) {
}
mainRendererContents.send('desktop:runtime-invalidated', event)
})
onRuntimeAuthExpired((event) => {
void forceLoginWindowForAuthExpired(event.message).catch((error) => {
console.error('[desktop-main] auth-expired window transition failed', error)
})
})
await queueWindowModeSwitch(currentWindowMode)
initTray(() => {
revealActiveWindowSafely('tray')