Skip to content

Commit fc7d10b

Browse files
authored
Unable to get the currently logged-in user (#7159)
Fixes #6971
1 parent 504a158 commit fc7d10b

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/github/credentials.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,9 @@ export class CredentialStore extends Disposable {
391391
return result;
392392
}
393393

394-
public async isCurrentUser(username: string): Promise<boolean> {
395-
return (await this._githubAPI?.currentUser)?.login === username || (await this._githubEnterpriseAPI?.currentUser)?.login == username;
394+
public async isCurrentUser(authProviderId: AuthProvider, username: string): Promise<boolean> {
395+
const api = authProviderId === AuthProvider.github ? this._githubAPI : this._githubEnterpriseAPI;
396+
return (await api?.currentUser)?.login === username;
396397
}
397398

398399
public async getIsEmu(authProviderId: AuthProvider): Promise<boolean> {
@@ -407,14 +408,14 @@ export class CredentialStore extends Disposable {
407408
}
408409

409410
private setCurrentUser(github: GitHub): void {
410-
const getUser: ReturnType<typeof github.octokit.api.users.getAuthenticated> = new Promise(resolve => {
411+
const getUser: ReturnType<typeof github.octokit.api.users.getAuthenticated> = new Promise((resolve, reject) => {
411412
Logger.debug('Getting current user', CredentialStore.ID);
412413
github.octokit.call(github.octokit.api.users.getAuthenticated, {}).then(result => {
413414
Logger.debug(`Got current user ${result.data.login}`, CredentialStore.ID);
414415
resolve(result);
415416
}).catch(e => {
416-
vscode.window.showErrorMessage(vscode.l10n.t('Unable to get the currently logged in user, GitHub Pull Requests will not work correctly'));
417417
Logger.error(`Failed to get current user: ${e}, ${e.message}`, CredentialStore.ID);
418+
reject(e);
418419
});
419420
});
420421
github.currentUser = getUser.then(result => convertRESTUserToAccount(result.data));

src/github/githubRepository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,8 +1469,8 @@ export class GitHubRepository extends Disposable {
14691469
}
14701470
}
14711471

1472-
isCurrentUser(login: string): Promise<boolean> {
1473-
return this._credentialStore.isCurrentUser(login);
1472+
isCurrentUser(authProviderId: AuthProvider, login: string): Promise<boolean> {
1473+
return this._credentialStore.isCurrentUser(authProviderId, login);
14741474
}
14751475

14761476

src/github/issueModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class IssueModel<TItem extends Issue = Issue> {
194194

195195
canEdit(): Promise<boolean> {
196196
const username = this.author && this.author.login;
197-
return this.githubRepository.isCurrentUser(username);
197+
return this.githubRepository.isCurrentUser(this.remote.authProviderId, username);
198198
}
199199

200200
async createIssueComment(text: string): Promise<IComment> {

0 commit comments

Comments
 (0)