Files
gridpilot.gg/apps/website/hooks/auth/useForgotPassword.ts
2026-01-24 12:47:49 +01:00

22 lines
860 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 { ForgotPasswordDTO } from '@/lib/types/generated/ForgotPasswordDTO';
import { useMutation, UseMutationOptions } from '@tanstack/react-query';
export function useForgotPassword(
options?: Omit<UseMutationOptions<{ message: string; magicLink?: string }, ApiError, ForgotPasswordDTO>, 'mutationFn'>
) {
const authService = useInject(AUTH_SERVICE_TOKEN);
return useMutation<{ message: string; magicLink?: string }, ApiError, ForgotPasswordDTO>({
mutationFn: async (params) => {
const result = await authService.forgotPassword(params);
if (result.isErr()) {
throw result.getError();
}
return result.unwrap();
},
...options,
});
}