Mike Chilled
Mike Chilled

Reputation: 37

isEmailVerified does not perform its task properly. Verified email, still returning false

I am trying to do email verification with the help of firebase, this after you have registered. This code is then executed and then a new scene is applied with a button inside which checks if the email got verified. Here are both codes. Thanks in advance for any answer!! I gladly accept any advice!

More detailed error description: After checking the email by clicking on the link, it is not yet verified. I found that you had to use signInWithEmailAndPassword before using isEmailVerified in this post but, it still doesn’t work.

Registration:

public void registerByEmail(AppCompatActivity activity, Context context, String email, String password) {
        System.out.println(email + " " + password);
        AuthSupport.firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(task -> {
            if(task.isSuccessful()) {
                AuthSupport.firebaseAuth.signInWithEmailAndPassword(email, password);
                FirebaseUser firebaseUser = AuthSupport.firebaseAuth.getCurrentUser();
                Task<Void> voidTask = firebaseUser.sendEmailVerification()
                        .addOnSuccessListener(unused -> {
                            Toast.makeText(context, "Verification Email has been sent.", Toast.LENGTH_SHORT).show();
                            new VerificationEmailSupport().updateUIVerification(activity);
                        })
                        .addOnFailureListener(e -> Log.d("Error", "Cannot send verification email"));
    
                Toast.makeText(context, "Registration successful", Toast.LENGTH_SHORT).show();
    
    
            } else Toast.makeText(context, "Registration failed, try again later...", Toast.LENGTH_SHORT).show();
        });
    }

Verify button click-action code:

public void verifyEmail(View view, AuthSupport authSupport) {
    System.out.println("EXECUTING!");
    System.out.println(AuthSupport.firebaseAuth.getCurrentUser().getEmail() + " im checking for him! ");
    if(!AuthSupport.firebaseAuth.getCurrentUser().isEmailVerified()) {
        Toast.makeText(view.getContext(), "Check the email and retry again...", Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(view.getContext(), "Email verified successfully.", Toast.LENGTH_SHORT).show();
        authSupport.updateUI(view.getContext(), AuthSupport.firebaseAuth.getCurrentUser());
    }
}

Upvotes: 0

Views: 40

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599686

Verifying the email address happens outside of your application (typically in the user's default browser) and does not immediately update the user profile in your app.

The user profile is only updated when:

  • The user signs out and in again.
  • Once every hour, when the ID token is about to expire.
  • When you call reload on the user object. You can put a button in your UI to do this, or automatically call that, for example in the onResume of the activity.

Also see:

Upvotes: 1

Related Questions