aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/GoogleAuthenticationManager.tsx
diff options
context:
space:
mode:
authorAndy Rickert <andrew_rickert@brown.edu>2020-04-02 17:42:18 -0700
committerAndy Rickert <andrew_rickert@brown.edu>2020-04-02 17:42:18 -0700
commitfb329b1a8abca361d831c7ec1f1a9ea0f3d410cf (patch)
treee09138a0544fe3814b1bd1e95d59bc4c0e96f5ed /src/client/apis/GoogleAuthenticationManager.tsx
parent3a1dac48c00dbe81142da90f8b52bfae02ce1921 (diff)
parentb4958eac84339dd7a88c964a9c52e89481048f55 (diff)
merge
Diffstat (limited to 'src/client/apis/GoogleAuthenticationManager.tsx')
-rw-r--r--src/client/apis/GoogleAuthenticationManager.tsx46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx
index ce1277667..417dc3c3b 100644
--- a/src/client/apis/GoogleAuthenticationManager.tsx
+++ b/src/client/apis/GoogleAuthenticationManager.tsx
@@ -12,8 +12,8 @@ const prompt = "Paste authorization code here...";
@observer
export default class GoogleAuthenticationManager extends React.Component<{}> {
public static Instance: GoogleAuthenticationManager;
- @observable private openState = false;
private authenticationLink: Opt<string> = undefined;
+ @observable private openState = false;
@observable private authenticationCode: Opt<string> = undefined;
@observable private clickedState = false;
@observable private success: Opt<boolean> = undefined;
@@ -39,24 +39,18 @@ export default class GoogleAuthenticationManager extends React.Component<{}> {
const disposer = reaction(
() => this.authenticationCode,
async authenticationCode => {
- if (!authenticationCode) {
- return;
+ if (authenticationCode) {
+ disposer();
+ const { access_token, avatar, name } = await Networking.PostToServer("/writeGoogleAccessToken", { authenticationCode });
+ runInAction(() => {
+ this.avatar = avatar;
+ this.username = name;
+ this.hasBeenClicked = false;
+ this.success = false;
+ });
+ this.beginFadeout();
+ resolve(access_token);
}
- const { access_token, avatar, name } = await Networking.PostToServer(
- "/writeGoogleAccessToken",
- { authenticationCode }
- );
- runInAction(() => {
- this.avatar = avatar;
- this.username = name;
- });
- this.beginFadeout();
- disposer();
- resolve(access_token);
- action(() => {
- this.hasBeenClicked = false;
- this.success = false;
- });
}
);
});
@@ -86,26 +80,20 @@ export default class GoogleAuthenticationManager extends React.Component<{}> {
GoogleAuthenticationManager.Instance = this;
}
- private handleClick = () => {
- window.open(this.authenticationLink);
- setTimeout(() => this.hasBeenClicked = true, 500);
- }
-
- private handlePaste = action((e: React.ChangeEvent<HTMLInputElement>) => {
- this.authenticationCode = e.currentTarget.value;
- });
-
private get renderPrompt() {
return (
<div className={'authorize-container'}>
{this.displayLauncher ? <button
className={"dispatch"}
- onClick={this.handleClick}
+ onClick={() => {
+ window.open(this.authenticationLink);
+ setTimeout(() => this.hasBeenClicked = true, 500);
+ }}
style={{ marginBottom: this.clickedState ? 15 : 0 }}
>Authorize a Google account...</button> : (null)}
{this.clickedState ? <input
className={'paste-target'}
- onChange={this.handlePaste}
+ onChange={action(e => this.authenticationCode = e.currentTarget.value)}
placeholder={prompt}
/> : (null)}
{this.avatar ? <img