Handle auth state changes in all extension windows (#4987)

* Handle auth state changes in all extension windows

Addresses an issue where authentication state changes (login/logout) were not being properly propagated across all extension windows.

The `onDidChange` event handler for `clineAccountId` secret now checks if the secret was added/updated (login) or removed (logout).

- If the secret exists, `restoreRefreshTokenAndRetrieveAuthInfo` is called to restore auth info (login from another window).
- If the secret is removed, `handleDeauth` is called to handle logout for all windows.

This ensures that all extension windows are kept in sync with the current authentication state.

* changeset
This commit is contained in:
Bee authored and GitHub committed 2025-07-17 15:40:30 -07:00
1 parent 0b66faa1dd
commit 8e95c136a6
2 files changed
+16 -2

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Handle auth state changes in all extension windows
+11 -2
View File
@@ -691,9 +691,18 @@ export async function activate(context: vscode.ExtensionContext) {
)
context.subscriptions.push(
context.secrets.onDidChange((event) => {
context.secrets.onDidChange(async (event) => {
if (event.key === "clineAccountId") {
AuthService.getInstance(context)?.restoreRefreshTokenAndRetrieveAuthInfo()
// Check if the secret was removed (logout) or added/updated (login)
const secretValue = await context.secrets.get("clineAccountId")
const authService = AuthService.getInstance(context)
if (secretValue) {
// Secret was added or updated - restore auth info (login from another window)
authService?.restoreRefreshTokenAndRetrieveAuthInfo()
} else {
// Secret was removed - handle logout for all windows
authService?.handleDeauth()
}
}
}),
)