Skip to content

Commit 36d2f75

Browse files
committed
Fix "Bad credentials"
Fixes #3022
1 parent 4f9ac1f commit 36d2f75

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/github/credentials.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,24 @@ export class CredentialStore implements vscode.Disposable {
9797
} else {
9898
this._enterpriseSessionId = session.id;
9999
}
100-
const github = await this.createHub(session.accessToken, authProviderId);
100+
let github: GitHub | undefined;
101+
try {
102+
github = await this.createHub(session.accessToken, authProviderId);
103+
} catch (e) {
104+
if ((e.message === 'Bad credentials') && !getAuthSessionOptions.forceNewSession) {
105+
getAuthSessionOptions.forceNewSession = true;
106+
getAuthSessionOptions.silent = false;
107+
return this.initialize(authProviderId, getAuthSessionOptions);
108+
}
109+
}
101110
if (authProviderId === AuthProvider.github) {
102111
this._githubAPI = github;
103112
} else {
104113
this._githubEnterpriseAPI = github;
105114
}
106-
await this.setCurrentUser(github);
115+
if (github) {
116+
await this.setCurrentUser(github);
117+
}
107118
this._onDidInitialize.fire();
108119
} else {
109120
Logger.debug(`No GitHub${getGitHubSuffix(authProviderId)} token found.`, 'Authentication');

0 commit comments

Comments
 (0)