22 lines
814 B
TypeScript
22 lines
814 B
TypeScript
import { useInject } from '@/lib/di/hooks/useInject';
|
|
import { AUTH_SERVICE_TOKEN } from '@/lib/di/tokens';
|
|
import { ApiError } from '@/lib/gateways/api/base/ApiError';
|
|
import type { ResetPasswordDTO } from '@/lib/types/generated/ResetPasswordDTO';
|
|
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
|
|
|
|
export function useResetPassword(
|
|
options?: Omit<UseMutationOptions<{ message: string }, ApiError, ResetPasswordDTO>, 'mutationFn'>
|
|
) {
|
|
const authService = useInject(AUTH_SERVICE_TOKEN);
|
|
|
|
return useMutation<{ message: string }, ApiError, ResetPasswordDTO>({
|
|
mutationFn: async (params) => {
|
|
const result = await authService.resetPassword(params);
|
|
if (result.isErr()) {
|
|
throw result.getError();
|
|
}
|
|
return result.unwrap();
|
|
},
|
|
...options,
|
|
});
|
|
} |