Home > OS >  How to catch a firebase authentication multiple updates for flutter
How to catch a firebase authentication multiple updates for flutter

Time:11-28

I have this code here and I want to catch any exception if an error happens to either of these 2.

    final user = FirebaseAuth.instance.currentUser!;
    try {
      user.updateEmail(newEmail.text);
      user.updatePassword(newPassword.text);
      print("success");
    } on FirebaseAuthException catch (e) {
      print("error");
    }

problem is, it is not recognizing the error and just goes and print "success". How do I make sure that if 1 of them throws an exception, it prints "error"?

CodePudding user response:

Aren't those updates async? You can try:

try {
await Future.wait([ user.updateEmail(newEmail.text), user.updatePassword(newPassword.text)]).then(() => print('Success'))
} on FirebaseAuthException catch(e) print("error")
  • Related