From c6aaefecbd94c3cb7bbc2ea48c3c5914d97bebbb Mon Sep 17 00:00:00 2001 From: Philip Okugbe Date: Thu, 28 Nov 2024 20:35:53 +0000 Subject: [PATCH] fix: clear local cache on logout (#519) --- apps/client/src/features/auth/hooks/use-auth.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/client/src/features/auth/hooks/use-auth.ts b/apps/client/src/features/auth/hooks/use-auth.ts index 47ba52f3..63f06287 100644 --- a/apps/client/src/features/auth/hooks/use-auth.ts +++ b/apps/client/src/features/auth/hooks/use-auth.ts @@ -23,6 +23,7 @@ import { acceptInvitation } from "@/features/workspace/services/workspace-servic import Cookies from "js-cookie"; import { jwtDecode } from "jwt-decode"; import APP_ROUTE from "@/lib/app-route.ts"; +import { useQueryClient } from "@tanstack/react-query"; export default function useAuth() { const [isLoading, setIsLoading] = useState(false); @@ -30,6 +31,7 @@ export default function useAuth() { const [, setCurrentUser] = useAtom(currentUserAtom); const [authToken, setAuthToken] = useAtom(authTokensAtom); + const queryClient = useQueryClient(); const handleSignIn = async (data: ILogin) => { setIsLoading(true); @@ -136,7 +138,8 @@ export default function useAuth() { setAuthToken(null); setCurrentUser(null); Cookies.remove("authTokens"); - navigate(APP_ROUTE.AUTH.LOGIN); + queryClient.clear(); + window.location.replace(APP_ROUTE.AUTH.LOGIN);; }; const handleForgotPassword = async (data: IForgotPassword) => {