Home > other >  The sms code from firebase does not match
The sms code from firebase does not match

Time:10-19

I created a number sending activity and confirmation/otp fragment using firebase phone auth. When directed to the confirmation page, a 6-digit sms code from Firebase is sent to the phone number entered, but no matter what I do, the entered edittext and the codes from firebase do not match. When I leave the edit text blank, it redirects to the fragment I want as if it were correct. Can you help me where am I making a mistake? My codes in the confirmation fragment are as follows;

class FragmentRegisterTelOnay : Fragment() { var comingNumber = "" lateinit var auth : FirebaseAuth lateinit var callbacks : PhoneAuthProvider.OnVerificationStateChangedCallbacks var verificationID = "" var comingCode : String = "" override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? { var view = inflater.inflate(R.layout.fragment_register_activity_phone,container,false) view.tvKullaniciTelNo.setText(" 90" comingNumber) auth = Firebase.auth setupCallBack()

  view.ileriButton.setOnClickListener {
      if (comingCode.equals(editTextOnayKodu.text.toString())){

        EventBus.getDefault().postSticky(EventBusDataEvents.KayitBilgileriniGonder(" 90$comingNumber",null,verificationID,comingCode))
        val transaction = requireActivity().supportFragmentManager.beginTransaction()
        transaction.replace(R.id.telefonOnayKod,FragmentRegisterDetailPhone())
        transaction.addToBackStack("TelOnayfragmentEklendi")
        transaction.commit()}
        else{
          Toast.makeText(activity,"Wrong Code",Toast.LENGTH_LONG).show()
      }

  }

    val options = PhoneAuthOptions.newBuilder(auth)
        .setPhoneNumber(" 90" comingNumber)       // Phone number to verify
        .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
        .setActivity(requireActivity()) // Activity (for callback binding)
        .setCallbacks(callbacks)          // OnVerificationStateChangedCallbacks
        .build()
    PhoneAuthProvider.verifyPhoneNumber(options)

    return view
}

private fun setupCallBack() {
    callbacks = object : PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        override fun onVerificationCompleted(credential: PhoneAuthCredential) {
            if(!credential.smsCode.isNullOrEmpty()){
            comingCode = credential.smsCode!!
            progressBarOnayKod.visibility = View.GONE
            Log.e("Success","on verificationcompleted sms: "   comingCode)}
            else{
                Log.e("Error","onverification has not completed")
            }
        }

        override fun onVerificationFailed(e: FirebaseException) {
            Log.e("Error: ",e.localizedMessage)
            progressBarOnayKod.visibility = View.GONE
        }

        override fun onCodeSent(verificationId: String,token: PhoneAuthProvider.ForceResendingToken) {
            verificationID = verificationId
            progressBarOnayKod.visibility = View.VISIBLE
            Log.e("Codesent","oncodesent worked")
        }
    }
}

@Subscribe (sticky = true)
internal fun onTelefonEvent(kayitBilgileri: EventBusDataEvents.KayitBilgileriniGonder){
    comingNumber = kayitBilgileri.telNo.toString()
    Log.e("test",comingNumber)
}

override fun onAttach(context: Context) {
    super.onAttach(context)
    EventBus.getDefault().register(this)
}

override fun onDetach() {
    super.onDetach()
    EventBus.getDefault().unregister(this)
}

}

CodePudding user response:

first set the sha1 to firebase setting and generate google config.json then add to poject's root directory and add to build.gradle dependency. it'll work properly

resources: https://github.com/firebase/quickstart-android/issues/283

CodePudding user response:

test this code https://github.com/firebase/quickstart-android/tree/master/auth And matches your code

  • Related