From a33011a64f804c4d6d3408d82b1387cabcf91da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EB=AF=BC=EC=9A=B1?= Date: Tue, 8 Jun 2021 02:34:48 +0900 Subject: [PATCH] Fix validateToken to support enterprise server --- src/context/App.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/context/App.tsx b/src/context/App.tsx index 357a581ee..75da6910b 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -21,6 +21,7 @@ import { setAppearance } from '../utils/appearance'; import { setAutoLaunch } from '../utils/comms'; import { useInterval } from '../hooks/useInterval'; import { useNotifications } from '../hooks/useNotifications'; +import {generateGitHubAPIUrl} from "../utils/helpers"; const defaultAccounts: AuthState = { token: null, @@ -127,17 +128,14 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { ); const validateToken = useCallback( - async ({ token, hostname }: AuthTokenOptions) => { - await apiRequestAuth( - `https://api.${hostname}/notifications`, - 'HEAD', - token - ); - const updatedAccounts = addAccount(accounts, token, hostname); - setAccounts(updatedAccounts); - saveState(updatedAccounts, settings); - }, - [accounts, settings] + async ({token, hostname}: AuthTokenOptions) => { + const url = generateGitHubAPIUrl(hostname) + "notifications"; + await apiRequestAuth(url, 'HEAD', token); + const updatedAccounts = addAccount(accounts, token, hostname); + setAccounts(updatedAccounts); + saveState(updatedAccounts, settings); + }, + [accounts, settings] ); const logout = useCallback(() => {