@@ -267,7 +267,7 @@ export abstract class CloudIntegrationAuthenticationProvider<
267
267
}
268
268
269
269
protected override async fetchOrCreateSession (
270
- storedSession : ProviderAuthenticationSession | undefined ,
270
+ _storedSession : ProviderAuthenticationSession | undefined ,
271
271
descriptor ?: IntegrationAuthenticationSessionDescriptor ,
272
272
options ?:
273
273
| {
@@ -285,6 +285,14 @@ export abstract class CloudIntegrationAuthenticationProvider<
285
285
source ?: Sources ;
286
286
} ,
287
287
) : Promise < ProviderAuthenticationSession | undefined > {
288
+ if ( options ?. forceNewSession ) {
289
+ if ( ! ( await this . disconnectSession ( ) ) ) {
290
+ return undefined ;
291
+ }
292
+
293
+ void this . connectCloudIntegration ( false , options ?. source ) ;
294
+ return undefined ;
295
+ }
288
296
// TODO: This is a stopgap to make sure we're not hammering the api on automatic calls to get the session.
289
297
// Ultimately we want to timestamp calls to syncCloudIntegrations and use that to determine whether we should
290
298
// make the call or not.
@@ -293,10 +301,7 @@ export abstract class CloudIntegrationAuthenticationProvider<
293
301
? await this . fetchSession ( descriptor )
294
302
: undefined ;
295
303
296
- if ( shouldForceNewSession ( storedSession , session , options ) ) {
297
- // TODO: gk.dev doesn't yet support forcing a new session, so the user will need to disconnect and reconnect
298
- void this . connectCloudIntegration ( false , options ?. source ) ;
299
- } else if ( shouldCreateSession ( session , options ) ) {
304
+ if ( shouldCreateSession ( session , options ) ) {
300
305
const connected = await this . connectCloudIntegration ( true , options ?. source ) ;
301
306
if ( ! connected ) return undefined ;
302
307
session = await this . getSession ( descriptor , { source : options ?. source } ) ;
@@ -357,6 +362,16 @@ export abstract class CloudIntegrationAuthenticationProvider<
357
362
} ;
358
363
}
359
364
365
+ private async disconnectSession ( ) : Promise < boolean > {
366
+ const loggedIn = await this . container . subscription . getAuthenticationSession ( false ) ;
367
+ if ( ! loggedIn ) return false ;
368
+
369
+ const cloudIntegrations = await this . container . cloudIntegrations ;
370
+ if ( cloudIntegrations == null ) return false ;
371
+
372
+ return cloudIntegrations . disconnect ( this . authProviderId ) ;
373
+ }
374
+
360
375
private async openCompletionInput ( cancellationToken : CancellationToken ) {
361
376
const input = window . createInputBox ( ) ;
362
377
input . ignoreFocusOut = true ;
@@ -569,19 +584,6 @@ function convertStoredSessionToSession(
569
584
} ;
570
585
}
571
586
572
- function shouldForceNewSession (
573
- storedSession : ProviderAuthenticationSession | undefined ,
574
- newSession : ProviderAuthenticationSession | undefined ,
575
- options ?: { createIfNeeded ?: boolean ; forceNewSession ?: boolean } ,
576
- ) {
577
- return (
578
- options ?. forceNewSession &&
579
- storedSession != null &&
580
- newSession != null &&
581
- storedSession . accessToken === newSession . accessToken
582
- ) ;
583
- }
584
-
585
587
function shouldCreateSession (
586
588
storedSession : ProviderAuthenticationSession | undefined ,
587
589
options ?: { createIfNeeded ?: boolean ; forceNewSession ?: boolean } ,
0 commit comments