From b05a5c57176affe5d2b9e183cfc5392b412be07d Mon Sep 17 00:00:00 2001 From: Leonardo Christino <leomilho@gmail.com> Date: Tue, 24 Oct 2023 17:21:51 +0200 Subject: [PATCH] chore(auth): call to header api even in dev --- .../lib/data-access/authorization/useAuth.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libs/shared/lib/data-access/authorization/useAuth.tsx b/libs/shared/lib/data-access/authorization/useAuth.tsx index 31b0f330d..76cff7da8 100644 --- a/libs/shared/lib/data-access/authorization/useAuth.tsx +++ b/libs/shared/lib/data-access/authorization/useAuth.tsx @@ -25,7 +25,7 @@ export const useAuth = () => { const [isLogin, setLogin] = useState(false); const dispatch = useAppDispatch(); - useEffect(() => { + const handleError = (err: any) => { if (import.meta.env.SKIP_LOGIN) { console.warn('skipping login'); setLogin(true); @@ -38,8 +38,13 @@ export const useAuth = () => { }) ); return; + } else { + setLogin(false); + console.error(err); } + }; + useEffect(() => { fetch(`${domain}${useruri}/headers`, fetchSettings) .then((res) => res @@ -55,15 +60,9 @@ export const useAuth = () => { }) ); }) - .catch((err) => { - console.error(err); - setLogin(false); - }) + .catch(handleError) ) - .catch((err) => { - console.error(err); - setLogin(false); - }); + .catch(handleError); }, []); return isLogin; -- GitLab