Skip to content

Fix #498: Implement consistent logout experience across VS Code windows #563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: sync authentication state across VS Code windows
Fixes #498 by implementing event-driven authentication synchronization.

When a user logs out from one VS Code window, all other windows now
immediately show a clear 'You've been logged out of Coder!' notification
instead of confusing errors like 'Invalid argument uriOrString'.

Uses ctx.secrets.onDidChange to detect session token changes and
syncAuth() to update all windows consistently.

- Add syncAuth() function to handle auth state changes
- Listen for sessionToken changes via ctx.secrets.onDidChange
- Update REST client, VS Code contexts, and workspace providers
- Show consistent logout notifications across windows

Tested: A/B validation confirms fix eliminates confusing user experience.
  • Loading branch information
OyinloluB committed Jul 29, 2025
commit 2cb3a79ed1d613bc9de7c5ff432c9135ffb668f2
54 changes: 54 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,58 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
}
}
}

/**
* Synchronize authentication state across all VS Code windows.
* Fixes Issue #498 by ensuring consistent logout behavior when the session token changes.
*/
async function syncAuth() {
const url = storage.getUrl();
const token = await storage.getSessionToken();

// Update the REST client with current credentials
restClient.setHost(url || "");
restClient.setSessionToken(token || "");

// Determine authentication state
const isAuthenticated = !!(url && token);

// Update VS Code contexts to reflect current auth state
await vscode.commands.executeCommand(
"setContext",
"coder.authenticated",
isAuthenticated,
);

if (!isAuthenticated) {
// Clear owner context since user is not authenticated
await vscode.commands.executeCommand(
"setContext",
"coder.isOwner",
false,
);

// Show consistent logout notification across all windows
vscode.window
.showInformationMessage("You've been logged out of Coder!", "Login")
.then((action) => {
if (action === "Login") {
vscode.commands.executeCommand("coder.login");
}
});

vscode.commands.executeCommand("coder.refreshWorkspaces");
} else {
vscode.commands.executeCommand("coder.refreshWorkspaces");
}
}

// Listen for session token changes to sync auth state across windows
ctx.subscriptions.push(
ctx.secrets.onDidChange((e) => {
if (e.key === "sessionToken") {
syncAuth();
}
}),
);
}