From e50e3c1d8ce36bf5420decb549692907dc20049a Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Tue, 21 Mar 2023 17:00:34 +0700 Subject: [PATCH] fix(check device): return check device --- src/features/AuthStore/hooks/useAuth.tsx | 28 +++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/features/AuthStore/hooks/useAuth.tsx b/src/features/AuthStore/hooks/useAuth.tsx index 3014348f..54e701bf 100644 --- a/src/features/AuthStore/hooks/useAuth.tsx +++ b/src/features/AuthStore/hooks/useAuth.tsx @@ -42,7 +42,6 @@ import { } from 'requests' import { userManager } from '../config' -// eslint-disable-next-line import { needCheckNewDeviсe } from '../helpers' export const useAuth = () => { @@ -220,7 +219,6 @@ export const useAuth = () => { }) }, [logout]) - // eslint-disable-next-line const checkNewDevice = useCallback(async () => { const loadedUser = await userManager.getUser() if (!loadedUser) return @@ -230,18 +228,18 @@ export const useAuth = () => { }) }, [reChekNewDevice]) - // useEffect(() => { - // if (!needCheckNewDeviсe && !user) return undefined - // const startCheckDevice = setInterval(checkNewDevice, 20000) - // isNewDeviceLogin && clearInterval(startCheckDevice) - // return () => clearInterval(startCheckDevice) - // - // // eslint-disable-next-line react-hooks/exhaustive-deps - // }, [ - // checkNewDevice, - // isNewDeviceLogin, - // setIsNewDeviceLogin, - // ]) + useEffect(() => { + if (!needCheckNewDeviсe && !user) return undefined + const startCheckDevice = setInterval(checkNewDevice, 20000) + isNewDeviceLogin && clearInterval(startCheckDevice) + return () => clearInterval(startCheckDevice) + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ + checkNewDevice, + isNewDeviceLogin, + setIsNewDeviceLogin, + ]) useEffect(() => { // попытаемся обновить токен используя refresh_token @@ -290,7 +288,7 @@ export const useAuth = () => { }, [changeLang]) useEffect(() => { - fetchUserInfo() + readToken() && fetchUserInfo() }, [fetchUserInfo, user]) const auth = useMemo(() => ({