fix: clear saved creds when switching authType (#587)

This commit is contained in:
Mingholy
2025-09-12 16:34:53 +08:00
committed by GitHub
parent 4a96646732
commit adabd96a42
3 changed files with 32 additions and 1 deletions

View File

@@ -321,7 +321,8 @@ const ToolInfo: React.FC<ToolInfo> = ({
>
<Text color={nameColor} bold>
{name}
</Text>{' '}
</Text>
<Text> </Text>
<Text color={Colors.Gray}>{description}</Text>
</Text>
</Box>

View File

@@ -548,6 +548,17 @@ describe('oauth2', () => {
expect(updatedAccountData.old).toContain('test@example.com');
});
it('should handle Qwen module clearing gracefully', async () => {
// This test verifies that clearCachedCredentialFile doesn't throw
// when Qwen modules are available and can be cleared
// Since dynamic imports in tests are complex, we'll just verify
// that the function completes without error and doesn't throw
await expect(clearCachedCredentialFile()).resolves.not.toThrow();
// The actual Qwen clearing logic is tested separately in the Qwen module tests
});
it('should clear the in-memory OAuth client cache', async () => {
const mockSetCredentials = vi.fn();
const mockGetAccessToken = vi

View File

@@ -402,6 +402,25 @@ export async function clearCachedCredentialFile() {
await clearCachedGoogleAccount();
// Clear the in-memory OAuth client cache to force re-authentication
clearOauthClientCache();
/**
* Also clear Qwen SharedTokenManager cache and credentials file to prevent stale credentials
* when switching between auth types
* TODO: We do not depend on code_assist, we'll have to build an independent auth-cleaning procedure.
*/
try {
const { SharedTokenManager } = await import(
'../qwen/sharedTokenManager.js'
);
const { clearQwenCredentials } = await import('../qwen/qwenOAuth2.js');
const sharedManager = SharedTokenManager.getInstance();
sharedManager.clearCache();
await clearQwenCredentials();
} catch (qwenError) {
console.debug('Could not clear Qwen credentials:', qwenError);
}
} catch (e) {
console.error('Failed to clear cached credentials:', e);
}