@@ -9,7 +9,7 @@ import { registerThemingParticipant, IThemeService } from 'vs/platform/theme/com
9
9
import { MenuBarVisibility , getTitleBarStyle , IWindowOpenable , getMenuBarVisibility } from 'vs/platform/windows/common/windows' ;
10
10
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
11
11
import { IAction , Action , SubmenuAction , Separator } from 'vs/base/common/actions' ;
12
- import { addDisposableListener , Dimension , EventType } from 'vs/base/browser/dom' ;
12
+ import { addDisposableListener , Dimension , EventType , getCookieValue } from 'vs/base/browser/dom' ;
13
13
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
14
14
import { isMacintosh , isWeb , isIOS , isNative } from 'vs/base/common/platform' ;
15
15
import { IConfigurationService , IConfigurationChangeEvent } from 'vs/platform/configuration/common/configuration' ;
@@ -38,6 +38,8 @@ import { KeyCode } from 'vs/base/common/keyCodes';
38
38
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry' ;
39
39
import { IsWebContext } from 'vs/platform/contextkey/common/contextkeys' ;
40
40
import { ICommandService } from 'vs/platform/commands/common/commands' ;
41
+ import { ILogService } from 'vs/platform/log/common/log' ;
42
+ import { Cookie } from 'vs/server/common/cookie' ;
41
43
42
44
export abstract class MenubarControl extends Disposable {
43
45
@@ -312,7 +314,8 @@ export class CustomMenubarControl extends MenubarControl {
312
314
@IThemeService private readonly themeService : IThemeService ,
313
315
@IWorkbenchLayoutService private readonly layoutService : IWorkbenchLayoutService ,
314
316
@IHostService protected readonly hostService : IHostService ,
315
- @ICommandService commandService : ICommandService
317
+ @ICommandService commandService : ICommandService ,
318
+ @ILogService private readonly logService : ILogService
316
319
) {
317
320
super ( menuService , workspacesService , contextKeyService , keybindingService , configurationService , labelService , updateService , storageService , notificationService , preferencesService , environmentService , accessibilityService , hostService , commandService ) ;
318
321
@@ -711,6 +714,28 @@ export class CustomMenubarControl extends MenubarControl {
711
714
webNavigationActions . pop ( ) ;
712
715
}
713
716
717
+ webNavigationActions . push ( new Action ( 'logout' , localize ( 'logout' , "Log out" ) , undefined , true ,
718
+ async ( event ?: MouseEvent ) => {
719
+ const COOKIE_KEY = Cookie . Key ;
720
+ const loginCookie = 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
+
714
739
return webNavigationActions ;
715
740
}
716
741
0 commit comments