From 8e95c136a63e8d4088b3648c52a00dd67b95a801 Mon Sep 17 00:00:00 2001 From: Bee <68532117+abeatrix@users.noreply.github.com> Date: Thu, 17 Jul 2025 15:40:30 -0700 Subject: [PATCH] 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 --- .changeset/wise-impalas-watch.md | 5 +++++ src/extension.ts | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changeset/wise-impalas-watch.md diff --git a/.changeset/wise-impalas-watch.md b/.changeset/wise-impalas-watch.md new file mode 100644 index 00000000..c9c2d5f2 --- /dev/null +++ b/.changeset/wise-impalas-watch.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Handle auth state changes in all extension windows diff --git a/src/extension.ts b/src/extension.ts index 396a4eb7..dfa1a457 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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() + } } }), )