From 8d424c8cb4d178d5fb92b6543d63fa409eb6430b Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 4 Jun 2025 21:05:03 -0400 Subject: changed google authentication to not reload the page. --- src/client/apis/GoogleAuthenticationManager.tsx | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/client/apis/GoogleAuthenticationManager.tsx') 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 => { + public fetchOrGenerateAccessToken = async (): Promise => { 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.'); } }; -- cgit v1.2.3-70-g09d2