Android Firebase cannot refresh email verification status

青春壹個敷衍的年華 提交于 2019-12-12 12:27:48

问题


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:

  1. 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.
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!