Skip to content

Commit

Permalink
fix: github enterprise login (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Sep 14, 2023
1 parent fb354d7 commit e35c68b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { setAutoLaunch } from '../utils/comms';
import { useInterval } from '../hooks/useInterval';
import { useNotifications } from '../hooks/useNotifications';
import Constants from '../utils/constants';
import { generateGitHubAPIUrl } from '../utils/helpers';

const defaultAccounts: AuthState = {
token: null,
Expand Down Expand Up @@ -134,7 +135,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
const validateToken = useCallback(
async ({ token, hostname }: AuthTokenOptions) => {
await apiRequestAuth(
`https://api.${hostname}/notifications`,
`${generateGitHubAPIUrl(hostname)}notifications`,
'HEAD',
token
);
Expand Down
8 changes: 3 additions & 5 deletions src/hooks/useNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ export const useNotifications = (): NotificationsState => {
if (!isGitHubLoggedIn) {
return;
}
const url = `https://api.${Constants.DEFAULT_AUTH_OPTIONS.hostname}/${endpointSuffix}`;
const url = `${generateGitHubAPIUrl(Constants.DEFAULT_AUTH_OPTIONS.hostname)}${endpointSuffix}`;
return apiRequestAuth(url, 'GET', accounts.token);
}

function getEnterpriseNotifications() {
return accounts.enterpriseAccounts.map((account) => {
const hostname = account.hostname;
const token = account.token;
const url = `https://${hostname}/api/v3/${endpointSuffix}`;
return apiRequestAuth(url, 'GET', token);
const url = `${generateGitHubAPIUrl(account.hostname)}${endpointSuffix}`;
return apiRequestAuth(url, 'GET', account.token);
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { generateGitHubAPIUrl } from "./helpers";

const { remote } = require('electron');
const BrowserWindow = remote.BrowserWindow;

Expand Down Expand Up @@ -78,7 +80,7 @@ export const getUserData = async (
hostname: string
): Promise<User> => {
const response = await apiRequestAuth(
`https://api.${hostname}/user`,
`${generateGitHubAPIUrl(hostname)}user`,
'GET',
token
);
Expand Down

0 comments on commit e35c68b

Please sign in to comment.