aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/AuthenticationManager.tsx
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-10-09 16:53:16 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-10-09 16:53:16 -0400
commit70a142b84d01e89b56d027b24e37122fa90fe25b (patch)
treedd7fe13a72ad01b7a5ac96c54dcd8703a1a09622 /src/client/apis/AuthenticationManager.tsx
parent7763ddefcd14986573f9a0010c7691fa4715b94e (diff)
better authentication feedback, cleanup
Diffstat (limited to 'src/client/apis/AuthenticationManager.tsx')
-rw-r--r--src/client/apis/AuthenticationManager.tsx90
1 files changed, 0 insertions, 90 deletions
diff --git a/src/client/apis/AuthenticationManager.tsx b/src/client/apis/AuthenticationManager.tsx
deleted file mode 100644
index d8f6b675b..000000000
--- a/src/client/apis/AuthenticationManager.tsx
+++ /dev/null
@@ -1,90 +0,0 @@
-import { observable, action, reaction, runInAction } from "mobx";
-import { observer } from "mobx-react";
-import * as React from "react";
-import MainViewModal from "../views/MainViewModal";
-import { Opt } from "../../new_fields/Doc";
-import { Identified } from "../Network";
-
-const AuthenticationUrl = "https://accounts.google.com/o/oauth2/v2/auth";
-const prompt = "Please paste the external authetication code here...";
-
-@observer
-export default class AuthenticationManager extends React.Component<{}> {
- public static Instance: AuthenticationManager;
- @observable private openState = false;
- private authenticationLink: Opt<string> = undefined;
- @observable private authenticationCode: Opt<string> = undefined;
- @observable private clickedState = false;
-
- private set isOpen(value: boolean) {
- runInAction(() => this.openState = value);
- }
-
- private set hasBeenClicked(value: boolean) {
- runInAction(() => this.clickedState = value);
- }
-
- public executeFullRoutine = async (service: string) => {
- let response = await Identified.FetchFromServer(`/read${service}AccessToken`);
- // 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;
- return new Promise<string>(async resolve => {
- const disposer = reaction(
- () => this.authenticationCode,
- authenticationCode => {
- if (authenticationCode) {
- Identified.PostToServer(`/write${service}AccessToken`, { authenticationCode }).then(token => {
- this.isOpen = false;
- this.hasBeenClicked = false;
- resolve(token);
- disposer();
- });
- }
- }
- );
- });
- }
- // otherwise, we already have a valid, stored access token
- return response;
- }
-
- constructor(props: {}) {
- super(props);
- AuthenticationManager.Instance = this;
- }
-
- private handleClick = () => {
- window.open(this.authenticationLink);
- this.hasBeenClicked = true;
- }
-
- private handlePaste = action((e: React.ChangeEvent<HTMLInputElement>) => {
- this.authenticationCode = e.currentTarget.value;
- });
-
- private get renderPrompt() {
- return (
- <div style={{ display: "flex", flexDirection: "column" }}>
- <button onClick={this.handleClick}>Please click here to authorize a Google account...</button>
- {this.clickedState ? <input
- onChange={this.handlePaste}
- placeholder={prompt}
- style={{ marginTop: 15 }}
- /> : (null)}
- </div>
- );
- }
-
- render() {
- return (
- <MainViewModal
- isDisplayed={this.openState}
- interactive={true}
- contents={this.renderPrompt}
- />
- );
- }
-
-} \ No newline at end of file