From 372b4722a4bc80bf848c2fb9ea9aa1daed1698a3 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Sun, 19 Mar 2023 19:43:23 +0700 Subject: [PATCH] fix(black-screen): fix black screen after expire token --- src/features/AuthStore/hooks/useAuth.tsx | 2 +- src/helpers/callApi/logoutIfUnauthorized.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/features/AuthStore/hooks/useAuth.tsx b/src/features/AuthStore/hooks/useAuth.tsx index d2a6c5ad..3e7999b5 100644 --- a/src/features/AuthStore/hooks/useAuth.tsx +++ b/src/features/AuthStore/hooks/useAuth.tsx @@ -280,7 +280,7 @@ export const useAuth = () => { }, [changeLang]) useEffect(() => { - fetchUserInfo() + readToken() && fetchUserInfo() }, [fetchUserInfo, user]) const auth = useMemo(() => ({ diff --git a/src/helpers/callApi/logoutIfUnauthorized.tsx b/src/helpers/callApi/logoutIfUnauthorized.tsx index feffe52b..f7f68cdf 100644 --- a/src/helpers/callApi/logoutIfUnauthorized.tsx +++ b/src/helpers/callApi/logoutIfUnauthorized.tsx @@ -1,9 +1,11 @@ +import { removeToken } from '../token' + export const logoutIfUnauthorized = async (response: Response) => { /* отключили из-за доступа без авторизации */ - // if (response.status === 401 || response.status === 403) { - // removeToken() - // window.dispatchEvent(new Event('FORBIDDEN_REQUEST')) - // } + if (response.status === 401 || response.status === 403) { + removeToken() + window.dispatchEvent(new Event('FORBIDDEN_REQUEST')) + } const error = new Error(response.statusText) // eslint-disable-next-line no-console