问题
In my Android app, I am creating user and sending verification email. I want to proceed to the next page when the user has verified by clicking the link in the email received. However, the verification status didn't update so I cannot proceed. I have tried signing out and signing in again which works but I don't want to refresh the status in this way. Any ideas?
Here is my code:
public void onClickContinueBtn() {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.reload().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()) {
if(!user.isEmailVerified()){
// not verified block
// get into here even if verified
} else {
// email verified, go to next page
}
} else {
// do nothing, or show error
}
}
});
}
回答1:
I had same issue. I'm using FirebaseUI and automatically it creates user on Firebase DB even if email has not yet been verified. But Firebase give you possibility to check if email has been verified or not by means of method user.isEmailVerified
.Two possibilities:
- If you want to guarantee access to your app only when email is verified: you could open a dialog when user signedIn and wait for verification. To cancel dialog automatically (only when email is verified) you can add an observer to that variable and so you can give access to your app.
- If you give access to your app also without verification of email, you can check it with boolean isEmailVerified. Remember that you have to refresh current user with method reload() on FirebaseUser. Note that the update of that boolean is not instantaneous
来源:https://stackoverflow.com/questions/40859227/android-firebase-cannot-refresh-email-verification-status