updateEmail method

Future<AuthResultStatus?> updateEmail(
  1. {required String password,
  2. required String? newEmail}
)

Update the user's email to newEmail after reauthentication with password.

Returns a Future that resolves to an AuthResultStatus based on the success of the update.

Implementation

Future<AuthResultStatus?> updateEmail({
  required String password,
  required String? newEmail,
}) async {
  final User user = instance.currentUser!;
  final status = await reauthenticate(email: user.email!, password: password);
  if (status == AuthResultStatus.successful) {
    try {
      await user.verifyBeforeUpdateEmail(newEmail!).then((_) {
        sendVerificationMail();
        return AuthResultStatus.successful;
      });
    } on FirebaseAuthException catch (e) {
      // Use AuthExeptionHandler to handle error codes
      return handleExeption(e);
    }
  }
  return status;
}