requestChangePassword method

  1. @override
Future<RequestPasswordResponse> requestChangePassword(
  1. String email,
  2. BuildContext context
)

Request a password reset for the given email. Returns a RequestPasswordResponse with a boolean indicating whether the request was successful. If the request was not successful, the response will contain an Error object with the error title and message.

Implementation

@override
Future<RequestPasswordResponse> requestChangePassword(
  String email,
  BuildContext context,
) async {
  try {
    await auth.sendPasswordResetEmail(email: email);
    return const RequestPasswordResponse(requestSuccesfull: true);
  } on FirebaseAuthException catch (e) {
    requestPasswordError = switch (e.code) {
      'invalid-email' => RequestPasswordResponse(
          requestSuccesfull: false,
          requestPasswordError: Error(
            title: translationsService.changePasswordInvalidEmailTitle,
            message: translationsService.changePasswordInvalidEmailMessage,
          ),
        ),
      'user-not-found' => RequestPasswordResponse(
          requestSuccesfull: false,
          requestPasswordError: Error(
            title: translationsService.changePasswordUserNotFoundTitle,
            message: translationsService.changePasswordUserNotFoundMessage,
          ),
        ),
      _ => RequestPasswordResponse(
          requestSuccesfull: false,
          requestPasswordError: Error(
            title: translationsService.changePasswordErrorTitle,
            message: translationsService.changePasswordErrorMessage,
          ),
        ),
    };
    return requestPasswordError!;
  }
}