aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/apis/GoogleAuthenticationManager.tsx23
-rw-r--r--src/client/util/SettingsManager.tsx2
-rw-r--r--src/client/views/nodes/TaskBox.tsx11
3 files changed, 23 insertions, 13 deletions
diff --git a/src/client/apis/GoogleAuthenticationManager.tsx b/src/client/apis/GoogleAuthenticationManager.tsx
index a93e03e60..ffec07512 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.');
}
};
diff --git a/src/client/util/SettingsManager.tsx b/src/client/util/SettingsManager.tsx
index 9e79fd870..f54dea90c 100644
--- a/src/client/util/SettingsManager.tsx
+++ b/src/client/util/SettingsManager.tsx
@@ -40,7 +40,7 @@ export class SettingsManager extends React.Component<object> {
@observable private _activeTab = 'Accounts';
@observable private _isOpen = false;
- private googleAuthorize = action(() => GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken(true));
+ private googleAuthorize = action(() => GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken());
public closeMgr = action(() => {
this._isOpen = false;
diff --git a/src/client/views/nodes/TaskBox.tsx b/src/client/views/nodes/TaskBox.tsx
index 8855e43c8..df81d9c69 100644
--- a/src/client/views/nodes/TaskBox.tsx
+++ b/src/client/views/nodes/TaskBox.tsx
@@ -6,7 +6,6 @@ import { DocumentType } from '../../documents/DocumentTypes';
import { FieldView } from './FieldView';
import { DateField } from '../../../fields/DateField';
import { Doc } from '../../../fields/Doc';
-import { Networking } from '../../Network';
import './TaskBox.scss';
import { GoogleAuthenticationManager } from '../../apis/GoogleAuthenticationManager';
@@ -324,6 +323,16 @@ export class TaskBox extends React.Component<TaskBoxProps> {
console.log('GT button clicked');
try {
const token = await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken();
+ if (token === undefined) {
+ const listener = () => {
+ if (confirm('✅ Try again?')) {
+ // refactor this click function and call it again
+ }
+ window.removeEventListener('focusin', listener);
+ };
+ setTimeout(() => window.addEventListener('focusin', listener), 100);
+ return;
+ }
console.log('Got token', token);
const response = await fetch('/googleTasks/create', {