diff --git a/client/src/context/authContextProvider.tsx b/client/src/context/authContextProvider.tsx index 085436b..c488370 100644 --- a/client/src/context/authContextProvider.tsx +++ b/client/src/context/authContextProvider.tsx @@ -103,8 +103,7 @@ export const AuthContextProvider = ({ }) .catch((data: ErrorResponse) => { if (data.error) { - setToken(null); - localStorage.clear(); + signout(); } }); }, [token]); diff --git a/client/src/utils/api/api-handler.ts b/client/src/utils/api/api-handler.ts index 0ef2bed..a4f95d6 100644 --- a/client/src/utils/api/api-handler.ts +++ b/client/src/utils/api/api-handler.ts @@ -47,6 +47,11 @@ export const APIHandler = ( }, }); }); + + if(res.status === 401) { + localStorage.clear(); + window.location.pathname = "/sign-in"; + } } }); });