Skip to content

Commit b560079

Browse files
committed
feat(auth): account scopes and expired pat workflow
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 5d8b620 commit b560079

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/renderer/routes/Accounts.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ export const AccountsRoute: FC = () => {
142142
state: { account },
143143
});
144144
case 'OAuth App':
145-
return navigate('/login-oauth-app', { replace: true });
145+
return navigate('/login-oauth-app', {
146+
replace: true,
147+
state: { account },
148+
});
146149
default:
147150
break;
148151
}

src/renderer/routes/LoginWithOAuthApp.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type FC, useCallback, useState } from 'react';
2-
import { useNavigate } from 'react-router-dom';
2+
import { useLocation, useNavigate } from 'react-router-dom';
33

44
import {
55
BookIcon,
@@ -27,7 +27,13 @@ import { Page } from '../components/layout/Page';
2727
import { Footer } from '../components/primitives/Footer';
2828
import { Header } from '../components/primitives/Header';
2929

30-
import type { ClientID, ClientSecret, Hostname, Token } from '../types';
30+
import type {
31+
Account,
32+
ClientID,
33+
ClientSecret,
34+
Hostname,
35+
Token,
36+
} from '../types';
3137
import type { LoginOAuthWebOptions } from '../utils/auth/types';
3238

3339
import {
@@ -39,6 +45,10 @@ import {
3945
import { openExternalLink } from '../utils/comms';
4046
import { rendererLogError } from '../utils/logger';
4147

48+
interface LocationState {
49+
account?: Account;
50+
}
51+
4252
export interface IFormData {
4353
hostname: Hostname;
4454
clientId: ClientID;
@@ -78,14 +88,16 @@ export const validateForm = (values: IFormData): IFormErrors => {
7888

7989
export const LoginWithOAuthAppRoute: FC = () => {
8090
const navigate = useNavigate();
91+
const location = useLocation();
92+
const { account: reAuthAccount } = (location.state ?? {}) as LocationState;
8193

8294
const { loginWithOAuthApp } = useAppContext();
8395

8496
const [shouldMaskClientSecret, setShouldMaskClientSecret] = useState(true);
8597
const [isVerifyingCredentials, setIsVerifyingCredentials] = useState(false);
8698

8799
const [formData, setFormData] = useState({
88-
hostname: Constants.GITHUB_HOSTNAME,
100+
hostname: reAuthAccount?.hostname ?? Constants.GITHUB_HOSTNAME,
89101
clientId: '' as ClientID,
90102
clientSecret: '' as ClientSecret,
91103
} as IFormData);

src/renderer/utils/auth/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export async function addAccount(
210210
(a) => getAccountUUID(a) === newAccountUUID,
211211
);
212212

213-
if (existingIndex !== -1) {
213+
if (existingIndex >= 0) {
214214
// Clear the cached Octokit client so the new token is used
215215
clearOctokitClientCacheForAccount(accountList[existingIndex]);
216216
// Replace the existing account (e.g. re-authentication with a new token)

0 commit comments

Comments
 (0)