mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix: clear saved creds when switching authType (#587)
This commit is contained in:
@@ -321,7 +321,8 @@ const ToolInfo: React.FC<ToolInfo> = ({
|
|||||||
>
|
>
|
||||||
<Text color={nameColor} bold>
|
<Text color={nameColor} bold>
|
||||||
{name}
|
{name}
|
||||||
</Text>{' '}
|
</Text>
|
||||||
|
<Text> </Text>
|
||||||
<Text color={Colors.Gray}>{description}</Text>
|
<Text color={Colors.Gray}>{description}</Text>
|
||||||
</Text>
|
</Text>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -548,6 +548,17 @@ describe('oauth2', () => {
|
|||||||
expect(updatedAccountData.old).toContain('test@example.com');
|
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 () => {
|
it('should clear the in-memory OAuth client cache', async () => {
|
||||||
const mockSetCredentials = vi.fn();
|
const mockSetCredentials = vi.fn();
|
||||||
const mockGetAccessToken = vi
|
const mockGetAccessToken = vi
|
||||||
|
|||||||
@@ -402,6 +402,25 @@ export async function clearCachedCredentialFile() {
|
|||||||
await clearCachedGoogleAccount();
|
await clearCachedGoogleAccount();
|
||||||
// Clear the in-memory OAuth client cache to force re-authentication
|
// Clear the in-memory OAuth client cache to force re-authentication
|
||||||
clearOauthClientCache();
|
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) {
|
} catch (e) {
|
||||||
console.error('Failed to clear cached credentials:', e);
|
console.error('Failed to clear cached credentials:', e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user