2025-01-31 12:27:17 +00:00
|
|
|
import { client } from "@/lib/rpc";
|
|
|
|
import { InferResponseType } from "hono";
|
|
|
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
2025-02-01 02:03:13 +00:00
|
|
|
import { useRouter } from "next/navigation";
|
2025-01-31 12:27:17 +00:00
|
|
|
|
|
|
|
type ResponseType = InferResponseType<(typeof client.api.auth.logout)["$post"]>;
|
|
|
|
|
|
|
|
export const useLogout = () => {
|
2025-02-01 02:03:13 +00:00
|
|
|
const router = useRouter();
|
2025-01-31 12:27:17 +00:00
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
|
|
const mutation = useMutation<ResponseType, Error>({
|
|
|
|
mutationFn: async () => {
|
|
|
|
const response = await client.api.auth.logout["$post"]();
|
|
|
|
return await response.json();
|
|
|
|
},
|
|
|
|
onSuccess: () => {
|
2025-02-01 02:03:13 +00:00
|
|
|
router.refresh();
|
2025-01-31 12:27:17 +00:00
|
|
|
queryClient.invalidateQueries({ queryKey: ["current"] });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return mutation;
|
|
|
|
};
|