From 311f7049228799385effac6adf9aaf24719c62fe Mon Sep 17 00:00:00 2001 From: Zoia R Date: Tue, 6 Sep 2022 12:52:41 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20ott-2739-block-checkDevi?= =?UTF-8?q?ce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/AuthStore/hooks/useAuth.tsx | 9 +++++++-- src/requests/checkDevice.tsx | 6 ++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/features/AuthStore/hooks/useAuth.tsx b/src/features/AuthStore/hooks/useAuth.tsx index 6d191767..83248447 100644 --- a/src/features/AuthStore/hooks/useAuth.tsx +++ b/src/features/AuthStore/hooks/useAuth.tsx @@ -10,8 +10,10 @@ import type { User } from 'oidc-client' import { UserManager } from 'oidc-client' import isString from 'lodash/isString' +import isBoolean from 'lodash/isBoolean' import { PAGES } from 'config' +import { client } from 'config/clients' import { addLanguageUrlParam, @@ -149,8 +151,10 @@ export const useAuth = () => { checkDevice(loadedUser.access_token).catch((er:FailedResponse) => { if (er.error) return - setIsNewDeviceLogin(true) - setTimeout(logout, 10000) + if (isBoolean(er.ok) && !er.ok) { + setIsNewDeviceLogin(true) + setTimeout(logout, 10000) + } }) }, [logout, userManager]) @@ -164,6 +168,7 @@ export const useAuth = () => { }, [reChekNewDevice, userManager]) useEffect(() => { + if (client.name !== 'instat') return undefined const startCheckDevice = setInterval(checkNewDevice, 20000) isNewDeviceLogin && clearInterval(startCheckDevice) return () => clearInterval(startCheckDevice) diff --git a/src/requests/checkDevice.tsx b/src/requests/checkDevice.tsx index 905cac6a..d7f03574 100644 --- a/src/requests/checkDevice.tsx +++ b/src/requests/checkDevice.tsx @@ -18,9 +18,7 @@ export const checkDevice = async (token: string) => { const response = await fetch(url, config) - const body: SuccessResponse | FailedResponse = await response.json() + const body: SuccessResponse | FailedResponse | undefined = await response.json() - if (body.ok) return Promise.resolve() - - return Promise.reject(body) + return (body && !body.ok) ? Promise.reject(body) : Promise.resolve() }