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
|| 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`
}
}

@ -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
}, [

Loading…
Cancel
Save