diff options
author | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-04 22:30:11 -0400 |
---|---|---|
committer | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-04 22:30:11 -0400 |
commit | 745784b36e0f6fd2557ffe0d32cf11051627b148 (patch) | |
tree | afb4a23fdb801660b0017c6faefe50ac9e7a6531 /src/client/apis/GoogleAuthenticationManager.tsx | |
parent | eb9c93a635191ef9ec842592c4a85262811cf108 (diff) | |
parent | 488451f04d42642f11975e9532542a78622b16ef (diff) |
Merge branch 'task_nodes_aarav' of https://github.com/brown-dash/Dash-Web into task_nodes_aarav
Diffstat (limited to 'src/client/apis/GoogleAuthenticationManager.tsx')
-rw-r--r-- | src/client/apis/GoogleAuthenticationManager.tsx | 29 |
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))} />; } } |