diff --git a/src/features/AuthStore/helpers.tsx b/src/features/AuthStore/helpers.tsx index d8d08216..0f5784c6 100644 --- a/src/features/AuthStore/helpers.tsx +++ b/src/features/AuthStore/helpers.tsx @@ -54,11 +54,11 @@ const redirectUrl = () => { // @ts-ignore || Boolean(clientsForRedirect[client.name]) ): - return `${window.origin}/redirect` + return `${window.origin}` case (ENV === 'staging' || ENV === 'preproduction'): - return `https://${stageENV}.insports.tv/redirect` + return `https://${stageENV}.insports.tv` default: - return `https://${clientName}.tv/redirect` + return `https://${clientName}.tv` } } diff --git a/src/features/AuthStore/hooks/useAuth.tsx b/src/features/AuthStore/hooks/useAuth.tsx index 558d4df0..da11b4f1 100644 --- a/src/features/AuthStore/hooks/useAuth.tsx +++ b/src/features/AuthStore/hooks/useAuth.tsx @@ -158,6 +158,8 @@ export const useAuth = () => { } const signinRedirectCallback = useCallback(() => { + setPage(history.location.pathname) + userManager.signinRedirectCallback() .then((loadedUser) => { storeUser(loadedUser) @@ -171,7 +173,6 @@ export const useAuth = () => { markUserLoaded() setPage('') setSearch('') - // } }).catch(login) // eslint-disable-next-line react-hooks/exhaustive-deps }, [ @@ -181,7 +182,13 @@ export const useAuth = () => { ]) useEffect(() => { - const isRedirectedBackFromAuthProvider = history.location.pathname === '/redirect' + const urlSearch = new URLSearchParams(history.location.search) + const searchToken = urlSearch.get('access_token') + const searchRefToken = urlSearch.get('id_token') + const searchExp = urlSearch.get('expires_in') + + const isRedirectedBackFromAuthProvider = Boolean(searchToken && searchRefToken && searchExp) + isRedirectedBackFromAuthProvider ? signinRedirectCallback() : checkUser() // eslint-disable-next-line react-hooks/exhaustive-deps }, [