2025-01-30 11:38:49 +03:00
|
|
|
import { useMutation } from '@tanstack/react-query';
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-19 19:26:29 +03:00
|
|
|
import { KEYS } from '@/backend/configuration';
|
|
|
|
|
2025-02-12 20:53:31 +03:00
|
|
|
import { authApi } from './api';
|
|
|
|
import { IPasswordTokenDTO, IResetPasswordDTO } from './types';
|
2025-01-27 15:03:48 +03:00
|
|
|
|
|
|
|
export const useResetPassword = () => {
|
|
|
|
const validateMutation = useMutation({
|
2025-02-19 19:26:29 +03:00
|
|
|
mutationKey: [KEYS.auth, 'validate-token'],
|
2025-01-30 11:38:49 +03:00
|
|
|
mutationFn: authApi.validatePasswordToken
|
2025-01-27 15:03:48 +03:00
|
|
|
});
|
|
|
|
const resetMutation = useMutation({
|
2025-02-19 19:26:29 +03:00
|
|
|
mutationKey: [KEYS.auth, 'reset-password'],
|
2025-01-30 11:38:49 +03:00
|
|
|
mutationFn: authApi.resetPassword
|
2025-01-27 15:03:48 +03:00
|
|
|
});
|
|
|
|
return {
|
2025-02-11 20:16:11 +03:00
|
|
|
validateToken: (data: IPasswordTokenDTO) => validateMutation.mutateAsync(data),
|
|
|
|
resetPassword: (data: IResetPasswordDTO) => resetMutation.mutateAsync(data),
|
2025-01-29 16:18:41 +03:00
|
|
|
isPending: resetMutation.isPending || validateMutation.isPending,
|
2025-02-04 23:34:02 +03:00
|
|
|
error: resetMutation.error ?? validateMutation.error,
|
|
|
|
reset: resetMutation.reset
|
2025-01-27 15:03:48 +03:00
|
|
|
};
|
|
|
|
};
|