ronie arnibal
ronie arnibal

Reputation: 39

How to catch a firebase authentication multiple updates for flutter

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"?

Upvotes: 0

Views: 24

Answers (1)

ColdDarkness
ColdDarkness

Reputation: 331

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")

Upvotes: 1

Related Questions