Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: Clean up isSignedIn implementation #1850

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions auth/src/VSCodeAzureSubscriptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,29 @@ export class VSCodeAzureSubscriptionProvider extends vscode.Disposable implement
* checks all accounts for a session.
*/
public async isSignedIn(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean> {
async function silentlyCheckForSession(tenantId?: string, account?: vscode.AuthenticationSessionAccountInformation): Promise<boolean> {
return !!await getSessionFromVSCode([], tenantId, { createIfNone: false, silent: true, account });
}
const innerIsSignedIn = async () => {
// If no tenant or account is provided, then check all accounts for a session
if (!account && !tenantId) {
const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
if (accounts.length === 0) {
return false;
}

// If no tenant or account is provided, then check all accounts for a session
if (!account && !tenantId) {
const accounts = await vscode.authentication.getAccounts(getConfiguredAuthProviderId());
if (accounts.length === 0) {
return false;
}

for (const account of accounts) {
if (await this.isSignedIn(undefined, account)) {
return true;
for (const account of accounts) {
if (await silentlyCheckForSession(tenantId, account)) {
// If any account has a session, then return true because the user is signed in
return true;
}
}
}

return silentlyCheckForSession(tenantId, account);
}

const session = await getSessionFromVSCode([], tenantId, { createIfNone: false, silent: true, account });
return !!session;
return await innerIsSignedIn();
}

/**
Expand Down
Loading