File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,42 @@ export class SubscriptionAuthenticationProvider implements AuthenticationProvide
138138 }
139139 }
140140
141+ @debug ( )
142+ public async removeSessionsByScopes ( scopes ?: string [ ] ) {
143+ const cc = Logger . getCorrelationContext ( ) ;
144+
145+ try {
146+ scopes = scopes ?. sort ( ) ;
147+ const scopesKey = getScopesKey ( scopes ) ;
148+
149+ const removed : AuthenticationSession [ ] = [ ] ;
150+
151+ let index = 0 ;
152+
153+ const sessions = await this . _sessionsPromise ;
154+
155+ for ( const session of sessions ) {
156+ if ( getScopesKey ( session . scopes ) !== scopesKey ) {
157+ index ++ ;
158+ continue ;
159+ }
160+
161+ sessions . splice ( index , 1 ) ;
162+ removed . push ( session ) ;
163+ }
164+
165+ if ( removed . length === 0 ) return ;
166+
167+ await this . storeSessions ( sessions ) ;
168+
169+ this . _onDidChangeSessions . fire ( { added : [ ] , removed : removed , changed : [ ] } ) ;
170+ } catch ( ex ) {
171+ Logger . error ( ex , cc ) ;
172+ void window . showErrorMessage ( `Unable to sign out of GitLens+: ${ ex } ` ) ;
173+ throw ex ;
174+ }
175+ }
176+
141177 private _migrated : boolean | undefined ;
142178 async tryMigrateSession ( ) : Promise < AuthenticationSession | undefined > {
143179 if ( this . _migrated == null ) {
Original file line number Diff line number Diff line change @@ -282,6 +282,11 @@ export class SubscriptionService implements Disposable {
282282 if ( this . _session != null ) {
283283 void this . container . subscriptionAuthentication . removeSession ( this . _session . id ) ;
284284 this . _session = undefined ;
285+ } else {
286+ // Even if we don't have a session, make sure to remove any other matching sessions
287+ void this . container . subscriptionAuthentication . removeSessionsByScopes (
288+ SubscriptionService . authenticationScopes ,
289+ ) ;
285290 }
286291
287292 if ( reset && this . container . debugging ) {
You can’t perform that action at this time.
0 commit comments