fix: handle token expiry (#3847)

This commit is contained in:
Erez Rokah
2020-06-03 12:44:03 +03:00
committed by GitHub
parent 43ef28b5dc
commit 285c940562
20 changed files with 282 additions and 17 deletions

View File

@ -202,11 +202,15 @@ export default class API {
user(): Promise<{ name: string; login: string }> {
if (!this._userPromise) {
this._userPromise = this.request('/user') as Promise<GitHubUser>;
this._userPromise = this.getUser();
}
return this._userPromise;
}
getUser() {
return this.request('/user') as Promise<GitHubUser>;
}
async hasWriteAccess() {
try {
const result: Octokit.ReposGetResponse = await this.request(this.repoURL);

View File

@ -111,6 +111,19 @@ export default class GitHub implements Implementation {
return true;
}
async status() {
const auth =
(await this.api
?.getUser()
.then(user => !!user)
.catch(e => {
console.warn('Failed getting GitHub user', e);
return false;
})) || false;
return { auth };
}
authComponent() {
const wrappedAuthenticationPage = (props: Record<string, unknown>) => (
<AuthenticationPage {...props} backend={this} />