forgotPassword method

Future<void> forgotPassword({
  1. required String email,
})
inherited

Implementation

Future<void> forgotPassword({required String email}) async {
  if (email.isEmpty) {
    setLoading(isLoading: false, error: 'Email is required');
    return;
  }

  setLoading(isLoading: true, error: null);

  final result = await passwordService.forgotPassword(
    ForgotPasswordPayload(email: email),
  );

  await result.when(
    success: (_) {
      if (!ref.mounted) return;
      state = state.copyWith(email: email, isLoading: false, error: null);
      goToPage(VoAuthPageKeys.verifyResetPassword);
    },
    failure: (error) {
      if (!ref.mounted) return;
      setLoading(isLoading: false, error: error.message);
    },
  );
}