Couldn't catch new FlutterFire Firebase Auth

Viewed 1225

I've been trying to catch exception from the new https://firebase.flutter.dev/ Firebase Auth and failed. Not sure what went wrong, here is my code for signIn with email and password function:

    try {
      UserCredential userCredential = await _firebaseAuth
          .signInWithEmailAndPassword(email: email, password: password);
      if (userCredential != null) {
        _user = userCredential.user;
      }
    } on FirebaseAuthException catch (e) {
      print(e.code);
    } on PlatformException catch (e) {
      print(e.message);
    } catch (e) {
      print(e.toString());
    }
    return _user;
  } 
2 Answers

Have you check at firebase console authentication whether your user is listed there or not.

enter image description here

If it not that's the problem, you can add new user at the console and try again login with email and password u just add.

You can use something like this,

try {
  UserCredential userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(
    email: "barry.allen@example.com",
    password: "SuperSecretPassword!"
  );
} on FirebaseAuthException catch (e) {
  if (e.code == 'user-not-found') {
    print('No user found for that email.');
  } else if (e.code == 'wrong-password') {
    print('Wrong password provided for that user.');
  }
}

More Error Codes: https://firebase.google.com/docs/reference/js/firebase.auth.Auth#error-codes_12

Related