aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/GoogleAuthenticationManager.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/apis/GoogleAuthenticationManager.tsx')
-rw-r--r--src/client/apis/GoogleAuthenticationManager.tsx29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx
index a93e03e60..70e1ccc05 100644
--- a/src/client/apis/GoogleAuthenticationManager.tsx
+++ b/src/client/apis/GoogleAuthenticationManager.tsx
@@ -1,4 +1,4 @@
-import { action, IReactionDisposer, makeObservable, observable, reaction, runInAction } from 'mobx';
+import { action, IReactionDisposer, makeObservable, observable, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { Opt } from '../../fields/Doc';
@@ -8,7 +8,6 @@ import { MainViewModal } from '../views/MainViewModal';
import './GoogleAuthenticationManager.scss';
import { ObservableReactComponent } from '../views/ObservableReactComponent';
-const AuthenticationUrl = 'https://accounts.google.com/o/oauth2/v2/auth';
const prompt = 'Paste authorization code here...';
@observer
@@ -85,27 +84,29 @@ export class GoogleAuthenticationManager extends ObservableReactComponent<object
// return (response2 as { access_token: string }).access_token;
// };
- public fetchOrGenerateAccessToken = async (): Promise<string> => {
+ public fetchOrGenerateAccessToken = async (): Promise<string | undefined> => {
const response = await Networking.FetchFromServer('/readGoogleAccessToken');
-
+
// This will return a JSON object with { access_token, user_info } if already linked
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 (err) {
- console.warn('Not linked yet or invalid JSON. Redirecting to auth...');
+ } catch {
+ console.warn('Not linked yet or invalid JSON. open auth...');
// This is an auth URL — redirect the user to /refreshGoogle
if (typeof response === 'string' && response.startsWith('http')) {
- window.location.href = response;
- return ''; // Won’t be used — this page will reload anyway
+ if (window.confirm('Authorize Dash to access your Google tasks?')) {
+ window.open(response)?.focus();
+ return undefined;
+ }
}
-
+
throw new Error('Unable to fetch Google access token.');
}
};
@@ -182,11 +183,7 @@ export class GoogleAuthenticationManager extends ObservableReactComponent<object
}
render() {
- return (
- <div className="hell">
- <MainViewModal isDisplayed={this.openState} interactive={true} contents={this.renderPrompt} dialogueBoxStyle={this.dialogueBoxStyle} overlayStyle={{ zIndex: 1001 }} closeOnExternalClick={action(() => (this.isOpen = false))} />
- </div>
- );
+ return <MainViewModal isDisplayed={this.openState} interactive={true} contents={this.renderPrompt} dialogueBoxStyle={this.dialogueBoxStyle} overlayStyle={{ zIndex: 1001 }} closeOnExternalClick={action(() => (this.isOpen = false))} />;
}
}