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 all commits
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
54 changes: 54 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,60 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
storage,
);

/**
* 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();
}
}),
);

const myWorkspacesProvider = new WorkspaceProvider(
WorkspaceQuery.Mine,
restClient,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy