fix: redirect to login after logout

This commit is contained in:
2025-03-02 04:41:31 +07:00
parent 8c3458c27f
commit 04a10eadfd
2 changed files with 18 additions and 5 deletions
+2 -4
View File
@@ -13,7 +13,7 @@ import Button from "../ui/button";
import { themes } from "@/app/themes";
import appStore from "@/stores/app-store";
import garageLogo from "@/assets/garage-logo.svg";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useMutation } from "@tanstack/react-query";
import api from "@/lib/api";
import { toast } from "sonner";
import { useAuth } from "@/hooks/useAuth";
@@ -90,12 +90,10 @@ const Sidebar = () => {
};
const LogoutButton = () => {
const queryClient = useQueryClient();
const logout = useMutation({
mutationFn: () => api.post("/auth/logout"),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["auth"] });
window.location.href = "/auth/login";
},
onError: (err) => {
toast.error(err?.message || "Unknown error");