Skip to content

Commit 55a7733

Browse files
authored
refactor: use URL to build href (#1309)
1 parent 2447543 commit 55a7733

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/utils/auth/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('utils/auth/utils.ts', () => {
4747

4848
expect(loadURLMock).toHaveBeenCalledTimes(1);
4949
expect(loadURLMock).toHaveBeenCalledWith(
50-
'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read:user,notifications,repo',
50+
'https://github.com/login/oauth/authorize?client_id=FAKE_CLIENT_ID_123&scope=read%3Auser%2Cnotifications%2Crepo',
5151
);
5252

5353
expect(browserWindow.destroy).toHaveBeenCalledTimes(1);

src/utils/auth/utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ export function authGitHub(
2828
show: true,
2929
});
3030

31-
const githubUrl = `https://${authOptions.hostname}/login/oauth/authorize`;
32-
const authUrl = `${githubUrl}?client_id=${authOptions.clientId}&scope=${Constants.AUTH_SCOPE}`;
31+
const authUrl = new URL(`https://${authOptions.hostname}`);
32+
authUrl.pathname = '/login/oauth/authorize';
33+
authUrl.searchParams.append('client_id', authOptions.clientId);
34+
authUrl.searchParams.append('scope', Constants.AUTH_SCOPE.toString());
3335

3436
const session = authWindow.webContents.session;
3537
session.clearStorageData();
3638

37-
authWindow.loadURL(authUrl);
39+
authWindow.loadURL(authUrl.toString());
3840

3941
const handleCallback = (url: Link) => {
4042
const raw_code = /code=([^&]*)/.exec(url) || null;

0 commit comments

Comments
 (0)