OTP is not coming, I am getting the verification ID and the Testing number is also working

This is the function I am using for to generate OTP and submitting OTP. The OTP came once, but after that the OTP is not coming. I even tried 2 different country code and numbers.

class AuthService with ChangeNotifier {
  final FirebaseAuth _auth = FirebaseAuth.instance;
  //Sign In
  String userphone = "";
  String verificationId;
  String errorMessage = "";

  Future verifyPhone(String phonenumber) async {
    final PhoneVerificationFailed verificationFailed =
        (FirebaseAuthException authException) {
      print("Auth Exception is ${authException.message}");
    };

    final PhoneCodeSent codeSent =
        (String verificationId, [int forceResendingToken]) async {
      print("verification id is $verificationId");
      this.verificationId = verificationId;
    };

    final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
        (String verificationId) {
      this.verificationId = verificationId;
    };

    await _auth.verifyPhoneNumber(
      phoneNumber: "+7" + phonenumber,
      verificationCompleted: null,
      verificationFailed: verificationFailed,
      codeSent: codeSent,
      codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
      timeout: const Duration(seconds: 60),
    );
  }

  Future signIn({@required String smsCode, context}) async {
    AuthCredential authCredential = PhoneAuthProvider.credential(
      verificationId: verificationId,
      smsCode: smsCode,
    );
    UserCredential result = await _auth.signInWithCredential(authCredential);
    User user = result.user;
    await checkUser(result);
    return _userFromFirebase(user);
  }
  }
}

The custom Button I am using to trigger the generate otp. I tried on emulator as well as on my Real Device.

CustomButton(
                buttonName: "Generate OTP",
                function: () async {
                  if (_formKeySignIn.currentState.validate() &&
                      phonenumber.length == 10) {
                    Provider.of<AuthService>(context, listen: false).userphone =
                        phonenumber;
                    
                    Provider.of<AuthService>(context, listen: false)
                        .verifyPhone(phonenumber);

                    widget.changeView();
                  } else {
                    setState(() {
                      error = "Please enter a valid phone number";
                    });
                  }
                },
              ),


Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)