2025-01-21 20:33:05 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
import { authApi } from './api';
|
|
|
|
|
|
|
|
export const useLogout = () => {
|
2025-01-23 19:41:31 +03:00
|
|
|
const client = useQueryClient();
|
2025-01-21 20:33:05 +03:00
|
|
|
const mutation = useMutation({
|
|
|
|
mutationKey: ['logout'],
|
|
|
|
mutationFn: authApi.logout,
|
2025-01-23 19:41:31 +03:00
|
|
|
onSettled: async () => await client.invalidateQueries({ queryKey: [authApi.baseKey] })
|
2025-01-21 20:33:05 +03:00
|
|
|
});
|
|
|
|
return { logout: (onSuccess?: () => void) => mutation.mutate(undefined, { onSuccess }) };
|
|
|
|
};
|