2025-01-21 20:33:05 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
2025-01-29 21:30:41 +03:00
|
|
|
|
2025-01-30 21:00:59 +03:00
|
|
|
import { authApi, IUserLoginDTO } from './api';
|
2025-01-21 20:33:05 +03:00
|
|
|
|
|
|
|
export const useLogin = () => {
|
2025-01-23 19:41:31 +03:00
|
|
|
const client = useQueryClient();
|
2025-01-21 20:33:05 +03:00
|
|
|
const mutation = useMutation({
|
|
|
|
mutationKey: ['login'],
|
|
|
|
mutationFn: authApi.login,
|
2025-01-29 21:30:41 +03:00
|
|
|
onSettled: () => client.invalidateQueries({ queryKey: [authApi.baseKey] }),
|
2025-01-31 21:04:21 +03:00
|
|
|
onSuccess: () => client.resetQueries()
|
2025-01-21 20:33:05 +03:00
|
|
|
});
|
|
|
|
return {
|
2025-02-11 20:15:34 +03:00
|
|
|
login: (data: IUserLoginDTO) => mutation.mutateAsync(data),
|
2025-01-21 20:33:05 +03:00
|
|
|
isPending: mutation.isPending,
|
|
|
|
error: mutation.error,
|
|
|
|
reset: mutation.reset
|
|
|
|
};
|
|
|
|
};
|