feat: 🎸 ott-2739-block-checkDevice

keep-around/b214ac7012ef42593bee62c207888a2593bc5a38
Zoia R 3 years ago committed by Gitea
parent c2cafee358
commit 311f704922
  1. 9
      src/features/AuthStore/hooks/useAuth.tsx
  2. 6
      src/requests/checkDevice.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)

@ -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()
}

Loading…
Cancel
Save