aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/GoogleAuthenticationManager.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-06-04 21:05:03 -0400
committerbobzel <zzzman@gmail.com>2025-06-04 21:05:03 -0400
commit8d424c8cb4d178d5fb92b6543d63fa409eb6430b (patch)
treea2b34b3e161b316403956d7407df7d2afe27546c /src/client/apis/GoogleAuthenticationManager.tsx
parent09be9002b5aa8f5ad7c602bcef6b53bbe0398cd3 (diff)
changed google authentication to not reload the page.
Diffstat (limited to 'src/client/apis/GoogleAuthenticationManager.tsx')
-rw-r--r--src/client/apis/GoogleAuthenticationManager.tsx23
1 files changed, 12 insertions, 11 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.');
}
};