Skip to content

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

TypeScript

fix(desktop-app): require token removal before logout state

Josué8d93c54b6be7
diff --git a/desktop-app/src/__tests__/appService.bootstrap.test.ts b/desktop-app/src/__tests__/appService.bootstrap.test.ts
index 12c579342..33d6a2631 100644
--- a/desktop-app/src/__tests__/appService.bootstrap.test.ts
+++ b/desktop-app/src/__tests__/appService.bootstrap.test.ts
@@ -363,7 +363,7 @@ describe('AppService invitation configuration lookup', () => {
expect(getMe).not.toHaveBeenCalled()
})
- it('releases the logout guard when clearing the saved token fails', async () => {
+ it('preserves the session when clearing the saved token fails', async () => {
process.env.EXTERNAL_REST_API_BASE_URL = 'https://api.example.com'
process.env.RPC_PROXY_BASE_URL = 'https://rpc.example.com'
vi.resetModules()
@@ -373,21 +373,61 @@ describe('AppService invitation configuration lookup', () => {
import('../config.js'),
])
const service = new AppService() as unknown as {
- tokenStore: { clearSessionToken: ReturnType<typeof vi.fn> }
+ authClient: {
+ getMe: ReturnType<typeof vi.fn>
+ passwordLogin: ReturnType<typeof vi.fn>
+ }
+ tokenStore: {
+ clearSessionToken: ReturnType<typeof vi.fn>
+ getSessionToken: ReturnType<typeof vi.fn>
+ setSessionToken: ReturnType<typeof vi.fn>
+ }
rpcTokenManager: { clear: ReturnType<typeof vi.fn> }
+ updateDesktopGfsUploadState: ReturnType<typeof vi.fn>
logoutInProgress: boolean
+ passwordLogin: (email: string, password: string) => Promise<unknown>
logout: () => Promise<void>
+ getSessionState: () => Promise<unknown>
+ getCachedUserId: () => string | null
+ gfsDispatchBlocked: boolean
+ }
+ const me = {
+ id: 'user-1',
+ email: '[email protected]',
+ name: null,
+ picture: null,
+ teamId: 'team-1',
+ teamName: 'Marketing',
+ role: 'member',
}
+ const getMe = vi.fn().mockResolvedValue(me)
+ const getSessionToken = vi.fn().mockResolvedValue('saved-token')
+ service.authClient = {
+ passwordLogin: vi.fn().mockResolvedValue({ token: 'saved-token', me }),
+ getMe,
+ } as never
service.tokenStore = {
+ getSessionToken,
+ setSessionToken: vi.fn().mockResolvedValue(undefined),
clearSessionToken: vi.fn().mockRejectedValue(new Error('keychain unavailable')),
} as never
service.rpcTokenManager = { clear: vi.fn() } as never
+ service.updateDesktopGfsUploadState = vi.fn().mockResolvedValue(undefined)
+
+ await service.passwordLogin('[email protected]', 'password123')
+ expect(service.getCachedUserId()).toBe('user-1')
await expect(service.logout()).rejects.toThrow(/keychain unavailable/)
expect(service.tokenStore.clearSessionToken).toHaveBeenCalledWith(getActiveEnvKey(), {
legacyEnvKeys: [getActiveLegacyRestOnlyEnvKey()],
})
expect(service.logoutInProgress).toBe(false)
+
+ await expect(service.getSessionState()).resolves.toEqual({ authenticated: true, me })
+ expect(service.getCachedUserId()).toBe('user-1')
+ expect(getSessionToken).not.toHaveBeenCalled()
+ expect(getMe).not.toHaveBeenCalled()
+ expect(service.gfsDispatchBlocked).toBe(false)
})
it('shares one saved-session restore across concurrent session-state requests', async () => {
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index 7fc59f65c..af6f3b784 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -2078,8 +2078,13 @@ export class AppService {
const envKey = getActiveEnvKey()
const legacyEnvKeys = getActiveLegacyEnvKeys()
await this.suspendDesktopGfsUploadsForAuthBoundary()
+ try {
+ await this.tokenStore.clearSessionToken(envKey, { legacyEnvKeys })
+ } catch (error) {
+ if (this.sessionToken && this.me) this.activateGfsAuthScope()
+ throw error
+ }
this.clearAuthenticatedSessionState()
- await this.tokenStore.clearSessionToken(envKey, { legacyEnvKeys })
// Grants survive logout (they are keyed by userId), but every cached SDK
// result must not: the next user of this machine gets nothing of this one's.
tryGetPluginSdkRuntime()?.notifySessionChanged(false)