Skip to content

Commit 94e37ad

Browse files
committed
wip
1 parent 665d7a5 commit 94e37ad

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,5 @@ mb.on('ready', () => {
107107
app.setLoginItemSettings(settings);
108108
});
109109
});
110+
111+
// TODO - Implement protocol event handler https://www.electronjs.org/docs/latest/api/protocol

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
"main.js",
7373
"first-run.js"
7474
],
75+
"protocols": {
76+
"name": "Gitify",
77+
"schemes": ["gitify"]
78+
},
7579
"mac": {
7680
"category": "public.app-category.developer-tools",
7781
"icon": "assets/images/app-icon.icns",

src/routes/Login.tsx

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { KeyIcon, PersonIcon } from '@primer/octicons-react';
1+
import { KeyIcon, MarkGithubIcon, PersonIcon } from '@primer/octicons-react';
22
import { ipcRenderer } from 'electron';
3-
import { type FC, useContext, useEffect } from 'react';
3+
import { type FC, useCallback, useContext, useEffect } from 'react';
44
import { useNavigate } from 'react-router-dom';
55
import { Logo } from '../components/Logo';
66
import { Button } from '../components/fields/Button';
77
import { AppContext } from '../context/App';
8+
import { authGitHub, getGitHubAuthURL } from '../utils/auth/utils';
9+
import { openExternalLink } from '../utils/comms';
810

911
export const LoginRoute: FC = () => {
1012
const navigate = useNavigate();
@@ -17,14 +19,14 @@ export const LoginRoute: FC = () => {
1719
}
1820
}, [isLoggedIn]);
1921

20-
// FIXME: Temporarily disable Login with GitHub (OAuth) as it's currently broken and requires a rewrite - see #485 #561 #747
21-
/* const loginUser = useCallback(async () => {
22+
const loginUser = useCallback(async () => {
2223
try {
23-
await login();
24+
openExternalLink(getGitHubAuthURL());
25+
await authGitHub();
2426
} catch (err) {
2527
// Skip
2628
}
27-
}, []); */
29+
}, []);
2830

2931
return (
3032
<div className="flex flex-1 flex-col justify-center items-center p-4 bg-white dark:bg-gray-dark dark:text-white">
@@ -35,19 +37,13 @@ export const LoginRoute: FC = () => {
3537
</div>
3638

3739
<div className="font-semibold text-center text-sm italic">Login with</div>
38-
{
39-
// FIXME: Temporarily disable Login with GitHub (OAuth) as it's currently broken and requires a rewrite - see #485 #561 #747
40-
/*
41-
<Button
40+
<Button
4241
name="GitHub"
43-
icon={MarkGitHubIcon}
42+
icon={MarkGithubIcon}
4443
label="Login with GitHub"
45-
class="w-50 px-2 py-2 my-2 text-xs"
44+
class="py-2 mt-2"
4645
onClick={loginUser}
47-
/>
48-
*/
49-
}
50-
46+
/>
5147
<Button
5248
name="Personal Access Token"
5349
icon={KeyIcon}

src/utils/auth/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface LoginOAuthAppOptions {
66
hostname: string;
77
clientId: string;
88
clientSecret: string;
9+
redirect: string;
910
}
1011

1112
export interface LoginPersonalAccessTokenOptions {

src/utils/auth/utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Account, AuthState, GitifyUser } from '../../types';
44
import type { UserDetails } from '../../typesGitHub';
55
import { getAuthenticatedUser } from '../api/client';
66
import { apiRequest } from '../api/request';
7+
import { openExternalLink } from '../comms';
78
import { Constants } from '../constants';
89
import { getPlatformFromHostname } from '../helpers';
910
import type { AuthMethod, AuthResponse, AuthTokenResponse } from './types';
@@ -22,6 +23,9 @@ export const authGitHub = (
2223
const githubUrl = `https://${authOptions.hostname}/login/oauth/authorize`;
2324
const authUrl = `${githubUrl}?client_id=${authOptions.clientId}&scope=${Constants.AUTH_SCOPE}`;
2425

26+
console.log('ADAM HERE');
27+
openExternalLink(authUrl);
28+
2529
const session = authWindow.webContents.session;
2630
session.clearStorageData();
2731

@@ -138,6 +142,22 @@ export function removeAccount(auth: AuthState, account: Account): AuthState {
138142
};
139143
}
140144

145+
export function getGitHubAuthURL() {
146+
const authURL = new URL(`https://${Constants.DEFAULT_AUTH_OPTIONS.hostname}`);
147+
authURL.pathname = '/login/oauth/authorize';
148+
authURL.searchParams.append(
149+
'client_id',
150+
Constants.DEFAULT_AUTH_OPTIONS.clientId,
151+
);
152+
authURL.searchParams.append(
153+
'redirect_uri',
154+
Constants.DEFAULT_AUTH_OPTIONS.redirect,
155+
);
156+
authURL.searchParams.append('scope', Constants.AUTH_SCOPE.join(','));
157+
158+
return authURL.toString();
159+
}
160+
141161
export function getDeveloperSettingsURL(account: Account): string {
142162
const settingsURL = new URL(`https://${account.hostname}`);
143163

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const Constants = {
88
hostname: 'github.com',
99
clientId: process.env.OAUTH_CLIENT_ID,
1010
clientSecret: process.env.OAUTH_CLIENT_SECRET,
11+
redirect: 'gitify://auth/callback',
1112
},
1213

1314
GITHUB_API_BASE_URL: 'https://api.github.com',

0 commit comments

Comments
 (0)