From 903c7b87aa670de60e05915032c2ecba3b51fe28 Mon Sep 17 00:00:00 2001 From: Afonso Jorge Ramos Date: Fri, 24 Jul 2026 02:40:24 +0100 Subject: [PATCH] fix: drop cached forge clients on app reset Resetting the app wiped accounts but left authenticated Octokit clients cached in memory. Clear per-account forge client state on reset, mirroring removeAccount. --- src/renderer/stores/useAccountsStore.test.ts | 21 ++++++++++++++++++++ src/renderer/stores/useAccountsStore.ts | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/src/renderer/stores/useAccountsStore.test.ts b/src/renderer/stores/useAccountsStore.test.ts index 96138c0c6..7fcee606d 100644 --- a/src/renderer/stores/useAccountsStore.test.ts +++ b/src/renderer/stores/useAccountsStore.test.ts @@ -14,6 +14,7 @@ import type { GetAuthenticatedUserResponse } from '../utils/forges/github/types' import { getRecommendedScopeNames } from '../utils/auth/scopes'; import * as logger from '../utils/core/logger'; import * as apiClient from '../utils/forges/github/client'; +import { getAdapter } from '../utils/forges/registry'; import { DEFAULT_ACCOUNTS_STATE } from './defaults'; import useAccountsStore from './useAccountsStore'; @@ -264,5 +265,25 @@ describe('renderer/stores/useAccountsStore.ts', () => { expect(result.current).toMatchObject(DEFAULT_ACCOUNTS_STATE); expect(result.current.accounts).toEqual([]); }); + + test('should drop forge client state for every account', () => { + const onAccountTokenChangeSpy = vi + .spyOn(getAdapter(mockGitHubCloudAccount), 'onAccountTokenChange') + .mockImplementation(vi.fn()); + + useAccountsStore.setState({ + accounts: [mockGitHubCloudAccount, mockGitHubEnterpriseServerAccount], + }); + + const { result } = renderHook(() => useAccountsStore()); + + act(() => { + result.current.reset(); + }); + + expect(onAccountTokenChangeSpy).toHaveBeenCalledTimes(2); + expect(onAccountTokenChangeSpy).toHaveBeenCalledWith(mockGitHubCloudAccount); + expect(onAccountTokenChangeSpy).toHaveBeenCalledWith(mockGitHubEnterpriseServerAccount); + }); }); }); diff --git a/src/renderer/stores/useAccountsStore.ts b/src/renderer/stores/useAccountsStore.ts index a1920182e..196423ac8 100644 --- a/src/renderer/stores/useAccountsStore.ts +++ b/src/renderer/stores/useAccountsStore.ts @@ -166,6 +166,12 @@ const useAccountsStore = create()( }, reset: () => { + // Drop forge-specific HTTP client state (e.g. cached authenticated + // Octokit clients) for every account being wiped. + for (const account of get().accounts) { + getAdapter(account).onAccountTokenChange?.(account); + } + set({ ...DEFAULT_ACCOUNTS_STATE }); }, }),