diff options
Diffstat (limited to 'src/client/apis/GoogleAuthenticationManager.tsx')
-rw-r--r-- | src/client/apis/GoogleAuthenticationManager.tsx | 62 |
1 files changed, 19 insertions, 43 deletions
diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx index 23e658329..67a6e01e9 100644 --- a/src/client/apis/GoogleAuthenticationManager.tsx +++ b/src/client/apis/GoogleAuthenticationManager.tsx @@ -41,49 +41,6 @@ export class GoogleAuthenticationManager extends ObservableReactComponent<object this.openState && this.resetState(0, 0); } - // public fetchOrGenerateAccessToken = async (displayIfFound = false) => { - // const response = await Networking.FetchFromServer('/readGoogleAccessToken'); - // // if this is an authentication url, activate the UI to register the new access token - - // if (new RegExp(AuthenticationUrl).test(response)) { - // this.isOpen = true; - // this.authenticationLink = response; - - // // GETS STUCK AT THIS PROMISE!! - // return new Promise<string>(resolve => { - // this.disposer?.(); - // this.disposer = reaction( - // () => this.authenticationCode, - // async authenticationCode => { - // if (authenticationCode && /\d{1}\/[\w-]{55}/.test(authenticationCode)) { - // resolve(authenticationCode); - // this.disposer?.(); - // // const response2 = await Networking.PostToServer('/writeGoogleAccessToken', { authenticationCode }); - // // runInAction(() => { - // // this.success = true; - // // this.credentials = response2 as { user_info: { name: string; picture: string }; access_token: string }; - // // }); - // // resolve((response2 as { access_token: string }).access_token); - // this.resetState(); - // } - // } - // ); - // }); - // } - - // // otherwise, we already have a valid, stored access token and user info - // const response2 = JSON.parse(response) as { user_info: { name: string; picture: string }; access_token: string }; - // if (displayIfFound) { - // runInAction(() => { - // this.success = true; - // this.credentials = response2; - // }); - // this.resetState(-1, -1); - // this.isOpen = true; - // } - // return (response2 as { access_token: string }).access_token; - // }; - public fetchOrGenerateAccessToken = async (): Promise<string | undefined> => { const response = await Networking.FetchFromServer('/readGoogleAccessToken'); @@ -111,6 +68,25 @@ export class GoogleAuthenticationManager extends ObservableReactComponent<object } }; + public fetchAccessTokenSilently = async (): Promise<string | undefined> => { + const response = await Networking.FetchFromServer('/readGoogleAccessToken'); + + try { + const parsed = JSON.parse(response) as { access_token: string; user_info: { name: string; picture: string } }; + + runInAction(() => { + this.success = true; + this.credentials = parsed; + }); + + return parsed.access_token; + } catch { + // Do nothing — just return undefined silently + return undefined; + } + }; + + resetState = action((visibleForMS: number = 3000, fadesOutInMS: number = 500) => { if (!visibleForMS && !fadesOutInMS) { runInAction(() => { |