Skip to content

Commit 9f790fd

Browse files
committed
feat(lib/vscode): add log out to application menu
This adds a new option to the Application Menu called Log out. It deletes the code-server cookie and logs a user out.
1 parent 24dc208 commit 9f790fd

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

lib/vscode/src/vs/workbench/browser/parts/titlebar/menubarControl.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { registerThemingParticipant, IThemeService } from 'vs/platform/theme/com
99
import { MenuBarVisibility, getTitleBarStyle, IWindowOpenable, getMenuBarVisibility } from 'vs/platform/windows/common/windows';
1010
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1111
import { IAction, Action, SubmenuAction, Separator } from 'vs/base/common/actions';
12+
import * as DOM from 'vs/base/browser/dom';
1213
import { addDisposableListener, Dimension, EventType } from 'vs/base/browser/dom';
1314
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1415
import { isMacintosh, isWeb, isIOS, isNative } from 'vs/base/common/platform';
@@ -38,6 +39,7 @@ import { KeyCode } from 'vs/base/common/keyCodes';
3839
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
3940
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys';
4041
import { ICommandService } from 'vs/platform/commands/common/commands';
42+
import { ILogService } from 'vs/platform/log/common/log';
4143

4244
export abstract class MenubarControl extends Disposable {
4345

@@ -312,7 +314,8 @@ export class CustomMenubarControl extends MenubarControl {
312314
@IThemeService private readonly themeService: IThemeService,
313315
@IWorkbenchLayoutService private readonly layoutService: IWorkbenchLayoutService,
314316
@IHostService protected readonly hostService: IHostService,
315-
@ICommandService commandService: ICommandService
317+
@ICommandService commandService: ICommandService,
318+
@ILogService private readonly logService: ILogService
316319
) {
317320
super(menuService, workspacesService, contextKeyService, keybindingService, configurationService, labelService, updateService, storageService, notificationService, preferencesService, environmentService, accessibilityService, hostService, commandService);
318321

@@ -711,6 +714,28 @@ export class CustomMenubarControl extends MenubarControl {
711714
webNavigationActions.pop();
712715
}
713716

717+
webNavigationActions.push(new Action('logout', localize('logout', "Log out"), undefined, true,
718+
async (event?: MouseEvent) => {
719+
const COOKIE_KEY = 'key';
720+
const loginCookie = DOM.getCookieValue(COOKIE_KEY);
721+
722+
this.logService.info('Logging out of code-server');
723+
724+
if(loginCookie) {
725+
this.logService.info(`Removing cookie under ${COOKIE_KEY}`);
726+
727+
if (document && document.cookie) {
728+
// We delete the cookie by setting the expiration to a date/time in the past
729+
document.cookie = COOKIE_KEY +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
730+
window.location.href = '/login';
731+
} else {
732+
this.logService.warn('Could not delete cookie because document and/or document.cookie is undefined');
733+
}
734+
} else {
735+
this.logService.warn('Could not log out because we could not find cookie');
736+
}
737+
}))
738+
714739
return webNavigationActions;
715740
}
716741

0 commit comments

Comments
 (0)