fix(#677): auto authorize

pull/273/head
Rakov 2 years ago
parent efce351342
commit 806a2519b6
  1. 6
      src/features/AuthStore/helpers.tsx
  2. 11
      src/features/AuthStore/hooks/useAuth.tsx

@ -54,11 +54,11 @@ const redirectUrl = () => {
// @ts-ignore // @ts-ignore
|| Boolean(clientsForRedirect[client.name]) || Boolean(clientsForRedirect[client.name])
): ):
return `${window.origin}/redirect` return `${window.origin}`
case (ENV === 'staging' || ENV === 'preproduction'): case (ENV === 'staging' || ENV === 'preproduction'):
return `https://${stageENV}.insports.tv/redirect` return `https://${stageENV}.insports.tv`
default: default:
return `https://${clientName}.tv/redirect` return `https://${clientName}.tv`
} }
} }

@ -158,6 +158,8 @@ export const useAuth = () => {
} }
const signinRedirectCallback = useCallback(() => { const signinRedirectCallback = useCallback(() => {
setPage(history.location.pathname)
userManager.signinRedirectCallback() userManager.signinRedirectCallback()
.then((loadedUser) => { .then((loadedUser) => {
storeUser(loadedUser) storeUser(loadedUser)
@ -171,7 +173,6 @@ export const useAuth = () => {
markUserLoaded() markUserLoaded()
setPage('') setPage('')
setSearch('') setSearch('')
// }
}).catch(login) }).catch(login)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [ }, [
@ -181,7 +182,13 @@ export const useAuth = () => {
]) ])
useEffect(() => { 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() isRedirectedBackFromAuthProvider ? signinRedirectCallback() : checkUser()
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [ }, [

Loading…
Cancel
Save