Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase Phone Auth not sending SMS Code

My Flutter Firebase Phone Auth is not working anymore. I don't know, but there may be some updates to the Firebase backend that I'm not aware of. I used to receive a verification code on a real device, but now I don't anymore. In my code, on a registration screen, I put in a phone number and press a button. Then, when phone number verification is complete, it should send me to the OTP page. I'm being sent to the OTP page alright, but I don't receive the SMS code on my phone.

Phone verification method

sendPhoneNumber(
    BuildContext context,
    String phoneNumber,
    navigateToOTPScreen,
  ) async {
    try {
      await FirebaseAuth.instance.verifyPhoneNumber(
        phoneNumber: phoneNumber,
        verificationCompleted: (PhoneAuthCredential phoneAuthCredential) async {
          await FirebaseAuth.instance.signInWithCredential(phoneAuthCredential);
        },
        verificationFailed: (error) {
          Fluttertoast.showToast(
              msg: "An error occured ...${error.message}",
              backgroundColor: Colors.red,
              textColor: Colors.black);
          print(error.message);
          throw Exception(error.message);
        },
        codeSent: (verificationId, forceResendingToken) {
          appData.verificationId = verificationId;
          Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => navigateToOTPScreen,
            ),
          );
        },
        codeAutoRetrievalTimeout: (verificationId) {},
      );
    } on FirebaseException catch (e) {
      Fluttertoast.showToast(
          msg: "${e.message}",
          backgroundColor: Colors.red,
          textColor: Colors.black);
    }
  }

I've tried this on both Android and IOS real devices. My Phonesign-in method on the Firebase console is enabled, and the SHA-1 and SHA-256 key for Android are in place. My Play Integrity for Android is also registered,d but I don't know what seems to be the problem.

like image 249
Eben Oasis Avatar asked Nov 02 '25 13:11

Eben Oasis


1 Answers

Since September 1 2024, projects on the free Spark plan can no longer send SMS for phone based sign-in. Check the Auth section in the Firebase pricing page for this.

enter image description here

To continue using phone based sign-in, you'll have to upgrade to the paid plan. Be sure to only enable SMS sending in regions where you expect active users and little/no abuse.

like image 176
Frank van Puffelen Avatar answered Nov 04 '25 10:11

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!