Portal/rsconcept/frontend/src/features/auth/backend/useLogin.tsx

20 lines
612 B
TypeScript
Raw Normal View History

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] }),
onSuccess: () => client.resetQueries()
2025-01-21 20:33:05 +03:00
});
return {
2025-02-03 18:17:07 +03:00
login: (data: IUserLoginDTO, onSuccess?: () => void) => mutation.mutate(data, { onSuccess }),
2025-01-21 20:33:05 +03:00
isPending: mutation.isPending,
error: mutation.error,
reset: mutation.reset
};
};