Have forceNewSession behave like createIfNone if no sessions are present (#148819)

* Have forceNewSession behave like createIfNone if no sessions are present

* include note in vscode.d.ts about forceNewSesssion behavior
This commit is contained in:
Tyler James Leonhardt
2022-05-05 13:30:14 -07:00
committed by GitHub
parent 9991dffebf
commit 6c8d8a2654
3 changed files with 24 additions and 21 deletions
@@ -210,9 +210,6 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
const supportsMultipleAccounts = this.authenticationService.supportsMultipleAccounts(providerId);
// Error cases
if (options.forceNewSession && !sessions.length) {
throw new Error('No existing sessions found.');
}
if (options.forceNewSession && options.createIfNone) {
throw new Error('Invalid combination of options. Please remove one of the following: forceNewSession, createIfNone');
}
@@ -247,7 +244,11 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu
if (options.createIfNone || options.forceNewSession) {
const providerName = this.authenticationService.getLabel(providerId);
const detail = (typeof options.forceNewSession === 'object') ? options.forceNewSession!.detail : undefined;
const isAllowed = await this.loginPrompt(providerName, extensionName, !!options.forceNewSession, detail);
// We only want to show the "recreating session" prompt if we are using forceNewSession & there are sessions
// that we will be "forcing through".
const recreatingSession = !!(options.forceNewSession && sessions.length);
const isAllowed = await this.loginPrompt(providerName, extensionName, recreatingSession, detail);
if (!isAllowed) {
throw new Error('User did not consent to login.');
}