signInWithCredential returns null without any error in flutter

Viewed 32

I'm using Firebase to sign in with phone number it does send OTP message but when I'm trying to sign with credentials using the OTP I got and the verification ID (they're not null they do have values) it returns null here (result is null) not throwing any errors here's my code

 static Future<UserCredential?> verifyOTP(
      String verificationId, String otp) async {
    UserCredential? result;
    try {
      print(otp);
      print(verificationId);

      PhoneAuthCredential credential = PhoneAuthProvider.credential(
        verificationId: verificationId,
        smsCode: otp,
      );
      result = await _firebaseAuth?.signInWithCredential(credential);
      User? user = _firebaseAuth?.currentUser;
      print('user $user');
      print('results $result');
    } on FirebaseAuthException catch (error) {
      print(error);
    }
    return result;
  }
1 Answers

By signInWithCredential do you mean Email and Password Firebase Authentication?

If so you should use signInWithEmailAndPassword Firebase Auth method. Example below:

try {
  await _firebaseAuth.signInWithEmailAndPassword(
    email: email,
    password: password,
  );
} catch (_) {
  throw const LogInWithEmailAndPasswordFailure();
}
Related