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

Loading…
Cancel
Save