Home > Mobile >  email is not verified
email is not verified

Time:03-06

in my application first i authenticate user email and then i am verifying user email i have set dialog activity to inform user to check email and verify email i have close button in dialog activity if user click on it dialog will be dismissed

i have implemented override fun onResume() method first activity and in this method i check user have verified email or not by auth.getInstance().currentUser.isEmailVerified

i ran this app i got email and successfully verify but in onResume() method auth.getInstance().currentUser.isEmailVerified returns false

auth.createUserWithEmailAndPassword(binding.email.text.toString(),binding.password.text.toString()).addOnCompleteListener { task->
    Log.d("userAuthenticated","yes")

    if(task.isSuccessful)
    {
        val currUser=auth.currentUser

        Log.d("TaskIsSuccessful","Yes")

        currUser!!.sendEmailVerification().addOnSuccessListener {
            Log.d("Emailissent","yes")

            uniqueFirebaseAuthId=task.result!!.user!!.uid.toString()

            val sentEmailbinding=ActivityEmailVarificationSignUpBinding.inflate(layoutInflater)

            val dialog = Dialog(this@SignUp)
            dialog.setContentView(sentEmailbinding.root)
            dialog.setCanceledOnTouchOutside(true)
            dialog.setCancelable(false)

            sentEmailbinding.closebtn.setOnClickListener{
                dialog.dismiss()
                Log.d("Iamback","Yes")
            }
            dialog.show()

            Log.d("verified",currUser.isEmailVerified.toString())

            Log.d("Dialogshown","yes")
            Log.d("uniqueFirebaseAuthValue","${uniqueFirebaseAuthId} ")
        }.addOnFailureListener {
            Log.d("emailauthverification",it.toString())
        }
    }
    task.addOnFailureListener {
        Log.d("TaskFail",it.toString())
    }

onResume() function

override fun onResume() {
    super.onResume()

    val userEnterdName=binding.uiqueusername.toString()

    val currUser=FirebaseAuth.getInstance().currentUser

    if(currUser!!.isEmailVerified) {
        val verifiedUser=UseratFirebase(userEnterdName,binding.email.toString(),binding.password.toString())

        val uniqueAuthId=uniqueFirebaseAuthId.toString()

        database.reference.child("users").child(uniqueAuthId).setValue(verifiedUser).addOnSuccessListener {
            val intent=Intent(this@SignUp,SignIn::class.java)
            intent.putExtra("Email",binding.email.text.toString())
            intent.putExtra("password",binding.email.toString())
        }.addOnFailureListener {
            Toast.makeText(this@SignUp,"Error occured while stroting data",Toast.LENGTH_LONG).show()
        }
    }
    else
    {
        Log.d("Curruser", "${currUser.toString() } -> ${currUser.isEmailVerified}")

        Toast.makeText(this@SignUp,"Please verify Your Account",Toast.LENGTH_LONG).show()
    }
}

CodePudding user response:

Verifying the user's email address happens in another application (you click the link in your mail app, and then it verifies that action in the browser), so you app is not aware of it right away.

The information is encoded in the user's ID token, which is refreshed automatically every hour, or when the user signs in again. So you can either wait/force the user to sign in again, or you can tell the SDK to refresh the token by calling user.getIdToken(true) or user.reload().

  • Related