fix(#274): fix redirect after authrorization

pull/79/head
Andrei Dekterev 3 years ago committed by Gitea
parent 7155a80a29
commit cab081346e
  1. 38
      src/features/AuthStore/hooks/useAuth.tsx

@ -56,17 +56,14 @@ export const useAuth = () => {
}, [userManager, lang]) }, [userManager, lang])
const logout = useCallback((key?: string) => { const logout = useCallback((key?: string) => {
if (history.location.pathname === '/') {
setSearch(history.location.search)
}
setPage(history.location.pathname) setPage(history.location.pathname)
userManager.clearStaleState() userManager.clearStaleState()
userManager.createSigninRequest().then(({ url }) => { userManager.createSigninRequest().then(({ url }) => {
const urlWithLang = addLanguageUrlParam(lang, url) const urlWithLang = addLanguageUrlParam(lang, url)
userManager.signoutRedirect({ post_logout_redirect_uri: urlWithLang }) userManager.signoutRedirect({ post_logout_redirect_uri: urlWithLang })
}) })
removeToken()
if (key !== 'saveToken') { if (key !== 'saveToken') {
removeToken()
removeCookie('access_token') removeCookie('access_token')
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@ -140,46 +137,33 @@ export const useAuth = () => {
.then((loadedUser) => { .then((loadedUser) => {
storeUser(loadedUser) storeUser(loadedUser)
queryParamStorage.clear() queryParamStorage.clear()
history.replace(PAGES.home) if (page.includes(PAGES.useraccount)) {
markUserLoaded() history.push(PAGES.home)
if (page) { } else {
const route = `${page}${page === '/' ? search : ''}` const route = `${page}${page === '/' ? search : ''}`
history.push(route) history.push(route)
setPage('')
setSearch('')
} }
markUserLoaded()
setPage('')
setSearch('')
// }
}).catch(login) }).catch(login)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ }, [
userManager, userManager,
login, login,
storeUser, storeUser,
history,
markUserLoaded, markUserLoaded,
page,
search,
setPage,
setSearch,
]) ])
useEffect(() => { useEffect(() => {
const isRedirectedBackFromAuthProvider = history.location.pathname === '/redirect' const isRedirectedBackFromAuthProvider = history.location.pathname === '/redirect'
if (isRedirectedBackFromAuthProvider) { isRedirectedBackFromAuthProvider ? signinRedirectCallback() : checkUser()
signinRedirectCallback() // eslint-disable-next-line react-hooks/exhaustive-deps
} else {
checkUser().catch(async () => {
if (history.location.pathname === '/') {
setSearch(history.location.search)
}
setPage(history.location.pathname)
})
}
}, [ }, [
checkUser, checkUser,
signinRedirectCallback, signinRedirectCallback,
login, login,
setPage,
setSearch,
history,
]) ])
const reChekNewDevice = useCallback(async () => { const reChekNewDevice = useCallback(async () => {

Loading…
Cancel
Save