Home » Java » java – Firebase: How to check if user email is verified-Exceptionshub

java – Firebase: How to check if user email is verified-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I am trying to check if the user email has been verified. However, I am not sure where to add this part of code in.

FirebaseUser user = mAuth.getCurrentUser();
                if(!user.isEmailVerified()){//check if the email is verified

                Toast.makeText(MainActivity.this,"Please verify your email",Toast.LENGTH_SHORT).show();

When I add it into AuthListener and signInWithEmailAndPassword, I get “Attempt to invoke virtual method ‘boolean com.google.firebase.auth.FirebaseUser.isEmailVerified()’ on a null object reference” error

        firebaseAuthListener = new FirebaseAuth.AuthStateListener() {//if the login status change
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser users = FirebaseAuth.getInstance().getCurrentUser();

                if (users!=null){
                    Intent intent = new Intent(MainActivity.this,MapActivity.class);
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(MainActivity.this, new OnCompleteListener<AuthResult>() {
                    public void onComplete(@NonNull Task<AuthResult> task) {

                            Toast.makeText(MainActivity.this,"Wrong email or password", Toast.LENGTH_SHORT).show();

Thank you for your help.

How to&Answers: