Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading