diff --git a/libs/shared/lib/data-access/authorization/useAuth.tsx b/libs/shared/lib/data-access/authorization/useAuth.tsx index 31b0f330d942151f98b2d392b7d08997b55cd0d0..76cff7da8bb301e5ee3daa47b71cb6cf51dd43eb 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;