Skip to content

Commit e35c68b

Browse files
authored
fix: github enterprise login (#533)
1 parent fb354d7 commit e35c68b

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/context/App.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { setAutoLaunch } from '../utils/comms';
2222
import { useInterval } from '../hooks/useInterval';
2323
import { useNotifications } from '../hooks/useNotifications';
2424
import Constants from '../utils/constants';
25+
import { generateGitHubAPIUrl } from '../utils/helpers';
2526

2627
const defaultAccounts: AuthState = {
2728
token: null,
@@ -134,7 +135,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
134135
const validateToken = useCallback(
135136
async ({ token, hostname }: AuthTokenOptions) => {
136137
await apiRequestAuth(
137-
`https://api.${hostname}/notifications`,
138+
`${generateGitHubAPIUrl(hostname)}notifications`,
138139
'HEAD',
139140
token
140141
);

src/hooks/useNotifications.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,14 @@ export const useNotifications = (): NotificationsState => {
5757
if (!isGitHubLoggedIn) {
5858
return;
5959
}
60-
const url = `https://api.${Constants.DEFAULT_AUTH_OPTIONS.hostname}/${endpointSuffix}`;
60+
const url = `${generateGitHubAPIUrl(Constants.DEFAULT_AUTH_OPTIONS.hostname)}${endpointSuffix}`;
6161
return apiRequestAuth(url, 'GET', accounts.token);
6262
}
6363

6464
function getEnterpriseNotifications() {
6565
return accounts.enterpriseAccounts.map((account) => {
66-
const hostname = account.hostname;
67-
const token = account.token;
68-
const url = `https://${hostname}/api/v3/${endpointSuffix}`;
69-
return apiRequestAuth(url, 'GET', token);
66+
const url = `${generateGitHubAPIUrl(account.hostname)}${endpointSuffix}`;
67+
return apiRequestAuth(url, 'GET', account.token);
7068
});
7169
}
7270

src/utils/auth.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { generateGitHubAPIUrl } from "./helpers";
2+
13
const { remote } = require('electron');
24
const BrowserWindow = remote.BrowserWindow;
35

@@ -78,7 +80,7 @@ export const getUserData = async (
7880
hostname: string
7981
): Promise<User> => {
8082
const response = await apiRequestAuth(
81-
`https://api.${hostname}/user`,
83+
`${generateGitHubAPIUrl(hostname)}user`,
8284
'GET',
8385
token
8486
);

0 commit comments

Comments
 (0)