Skip to content

Commit 5a1b9be

Browse files
authored
fix(login): pat (#2218)
Signed-off-by: Adam Setch <[email protected]>
1 parent 9e6a222 commit 5a1b9be

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/renderer/context/App.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ describe('renderer/context/App.tsx', () => {
201201
});
202202
});
203203

204+
afterEach(() => {
205+
jest.clearAllMocks();
206+
});
207+
204208
it('should call loginWithPersonalAccessToken', async () => {
205209
apiRequestAuthMock.mockResolvedValueOnce(null);
206210

@@ -230,15 +234,10 @@ describe('renderer/context/App.tsx', () => {
230234
expect(fetchNotificationsMock).toHaveBeenCalledTimes(1),
231235
);
232236

233-
expect(apiRequestAuthMock).toHaveBeenCalledTimes(2);
237+
expect(apiRequestAuthMock).toHaveBeenCalledTimes(1);
234238
expect(apiRequestAuthMock).toHaveBeenCalledWith(
235239
'https://api.github.com/notifications',
236240
'HEAD',
237-
'123-456',
238-
);
239-
expect(apiRequestAuthMock).toHaveBeenCalledWith(
240-
'https://api.github.com/user',
241-
'GET',
242241
'encrypted',
243242
);
244243
});

src/renderer/context/App.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
225225
const loginWithOAuthApp = useCallback(
226226
async (data: LoginOAuthAppOptions) => {
227227
const { authOptions, authCode } = await authGitHub(data);
228+
228229
const { token, hostname } = await getToken(authCode, authOptions);
230+
229231
const updatedAuth = await addAccount(auth, 'OAuth App', token, hostname);
230232
setAuth(updatedAuth);
231233
saveState({ auth: updatedAuth, settings });
@@ -235,7 +237,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
235237

236238
const loginWithPersonalAccessToken = useCallback(
237239
async ({ token, hostname }: LoginPersonalAccessTokenOptions) => {
238-
await headNotifications(hostname, token);
240+
const encryptedToken = (await encryptValue(token)) as Token;
241+
await headNotifications(hostname, encryptedToken);
242+
239243
const updatedAuth = await addAccount(
240244
auth,
241245
'Personal Access Token',
@@ -250,10 +254,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
250254

251255
const logoutFromAccount = useCallback(
252256
async (account: Account) => {
253-
// Remove notifications for account
254257
removeAccountNotifications(account);
255258

256-
// Remove from auth state
257259
const updatedAuth = removeAccount(auth, account);
258260
setAuth(updatedAuth);
259261
saveState({ auth: updatedAuth, settings });

0 commit comments

Comments
 (0)