.
This commit is contained in:
parent
7ba2ad5784
commit
738da90b23
@ -1,5 +1,5 @@
|
||||
import { AuthActionResponse, useAuth } from "@/lib/hooks";
|
||||
import { UseMutationOptions, useMutation } from "@tanstack/react-query";
|
||||
import { UseMutationOptions, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
@ -7,6 +7,7 @@ import { useQueryKey } from "../useQueryKey";
|
||||
|
||||
export const useLogout = (params?: UseMutationOptions<AuthActionResponse, Error>) => {
|
||||
const { onSuccess, onError, ...restParams } = params || {};
|
||||
const queryClient = useQueryClient();
|
||||
const keys = useQueryKey();
|
||||
const { logout } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
@ -16,6 +17,8 @@ export const useLogout = (params?: UseMutationOptions<AuthActionResponse, Error>
|
||||
mutationFn: logout,
|
||||
|
||||
onSuccess: async (data, variables, context) => {
|
||||
queryClient.clear();
|
||||
|
||||
const { success, redirectTo } = data;
|
||||
if (success && redirectTo) {
|
||||
navigate(redirectTo || "/", { replace: true });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user