From e7cf9911b49392d8fed91e8fc587d5d195495f3e Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sun, 11 Aug 2024 10:11:55 -0400 Subject: [PATCH] fix(auth): restore oauth2 flow functionality Signed-off-by: Adam Setch --- src/electron/main.js | 11 +++-- src/routes/Login.tsx | 34 +++++++-------- src/routes/LoginWithOAuthApp.tsx | 7 +++- src/routes/LoginWithPersonalAccessToken.tsx | 2 + src/routes/__snapshots__/Login.test.tsx.snap | 44 ++++++++++++++++++++ src/utils/auth/utils.ts | 1 + 6 files changed, 76 insertions(+), 23 deletions(-) diff --git a/src/electron/main.js b/src/electron/main.js index 34d0b975e..9bbb7bd99 100644 --- a/src/electron/main.js +++ b/src/electron/main.js @@ -17,10 +17,6 @@ const { autoUpdater } = require('electron-updater'); const { updateElectronApp } = require('update-electron-app'); log.initialize(); - -// TODO: Remove @electron/remote use - see #650 -require('@electron/remote/main').initialize(); - // Tray Icons const idleIcon = path.resolve( `${__dirname}/../../assets/images/tray-idleTemplate.png`, @@ -124,6 +120,13 @@ app.whenReady().then(async () => { mb.on('ready', () => { mb.app.setAppUserModelId('com.electron.gitify'); + /** + * TODO: Remove @electron/remote use - see #650 + * GitHub OAuth 2 Login Flows - Enable Remote Browser Window Launch + */ + require('@electron/remote/main').initialize(); + require('@electron/remote/main').enable(mb.window.webContents); + // Tray configuration mb.tray.setToolTip('Gitify'); mb.tray.setIgnoreDoubleClickEvents(true); diff --git a/src/routes/Login.tsx b/src/routes/Login.tsx index 6ac1f8793..2a661eb67 100644 --- a/src/routes/Login.tsx +++ b/src/routes/Login.tsx @@ -1,5 +1,6 @@ -import { KeyIcon, PersonIcon } from '@primer/octicons-react'; -import { type FC, useContext, useEffect } from 'react'; +import { KeyIcon, MarkGithubIcon, PersonIcon } from '@primer/octicons-react'; +import log from 'electron-log'; +import { type FC, useCallback, useContext, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { Button } from '../components/buttons/Button'; import { LogoIcon } from '../components/icons/LogoIcon'; @@ -9,7 +10,7 @@ import { showWindow } from '../utils/comms'; export const LoginRoute: FC = () => { const navigate = useNavigate(); - const { isLoggedIn } = useContext(AppContext); + const { loginWithGitHubApp, isLoggedIn } = useContext(AppContext); useEffect(() => { if (isLoggedIn) { @@ -18,14 +19,13 @@ export const LoginRoute: FC = () => { } }, [isLoggedIn]); - // FIXME: Temporarily disable Login with GitHub (OAuth) as it's currently broken and requires a rewrite - see #485 #561 #747 - /* const loginUser = useCallback(async () => { + const loginUser = useCallback(async () => { try { - await login(); + await loginWithGitHubApp(); } catch (err) { - // Skip + log.error('Auth: failed to login with GitHub', err); } - }, []); */ + }, [loginWithGitHubApp]); return (
@@ -36,18 +36,16 @@ export const LoginRoute: FC = () => {
Login with
- { - // FIXME: Temporarily disable Login with GitHub (OAuth) as it's currently broken and requires a rewrite - see #485 #561 #747 - /* -