|
|
|
|
@ -7,7 +7,7 @@ import { |
|
|
|
|
import { useHistory } from 'react-router' |
|
|
|
|
|
|
|
|
|
import type { User } from 'oidc-client' |
|
|
|
|
// @ts-ignore
|
|
|
|
|
// @ts-expect-error
|
|
|
|
|
import duel from 'dueljs' |
|
|
|
|
|
|
|
|
|
import isString from 'lodash/isString' |
|
|
|
|
@ -23,14 +23,12 @@ import { |
|
|
|
|
readToken, |
|
|
|
|
setCookie, |
|
|
|
|
removeCookie, |
|
|
|
|
TOKEN_KEY, |
|
|
|
|
} from 'helpers' |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
useLocalStore, |
|
|
|
|
useSessionStore, |
|
|
|
|
useToggle, |
|
|
|
|
useEventListener, |
|
|
|
|
} from 'hooks' |
|
|
|
|
|
|
|
|
|
import { useLexicsStore } from 'features/LexicsStore' |
|
|
|
|
@ -174,27 +172,6 @@ export const useAuth = () => { |
|
|
|
|
markUserLoaded, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
useEventListener({ |
|
|
|
|
callback: useCallback(async (e: StorageEvent) => { |
|
|
|
|
const loadedUser = await userManager.getUser() |
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
e.storageArea !== localStorage |
|
|
|
|
|| e.key !== TOKEN_KEY |
|
|
|
|
|| !e.newValue |
|
|
|
|
|| !loadedUser |
|
|
|
|
|| loadedUser.access_token === e.newValue |
|
|
|
|
) return |
|
|
|
|
|
|
|
|
|
userManager.storeUser({ |
|
|
|
|
...loadedUser, |
|
|
|
|
access_token: e.newValue, |
|
|
|
|
toStorageString: loadedUser.toStorageString, |
|
|
|
|
}) |
|
|
|
|
}, []), |
|
|
|
|
event: 'storage', |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const isRedirectedBackFromAuthProvider = history.location.pathname === '/redirect' |
|
|
|
|
isRedirectedBackFromAuthProvider ? signinRedirectCallback() : checkUser() |
|
|
|
|
|