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());
}
}