简体   繁体   English

如何在Firebase身份验证中更新用户的详细信息

[英]How to update the details of the user in Firebase Authentication

I am trying to develop an app in android studio using firebase where user verifies their email address after signup. 我正在尝试使用firebase在android studio中开发一个应用,用户在注册后会验证其电子邮件地址。 But even after verifying the email address, whenever I open the app again, it forwards me to the send email verification code page. 但是,即使在验证了电子邮件地址之后,每当我再次打开该应用程序时,它都会将我转发到“发送电子邮件验证码”页面。 However, if I clear app data, the same problem does not exist. 但是,如果我清除应用程序数据,则不存在相同的问题。

I tried using AuthStateListener (without knowing much about it) but it did not work. 我尝试使用AuthStateListener(对此一无所知),但是没有用。

here is the code that I tried. 这是我尝试过的代码。 I also tried it without the authstatelistener, but the same problem continued 我也尝试了没有authstatelistener的尝试,但是同样的问题仍然存在

   mAuth=FirebaseAuth.getInstance();
    user=mAuth.getCurrentUser();
    authStateListener=new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if(!user.isEmailVerified()){
                startActivity(new Intent(HomePage.this,VerifyEmail.class));
            }
        }
    };

It leads to the verify email page if I open it in the phone where I signed up. 如果我在注册的手机中打开该页面,则会进入验证电子邮件页面。 But after clearing the data, it does not forward me to that page. 但是清除数据后,它不会将我转发到该页面。

The reason for this issue is the FirebaseUser object is cached in the app by default. 出现此问题的原因是,默认情况下FirebaseUser对象在应用程序中缓存。 That's why there is no problem when the app data is cleared. 这就是为什么清除应用程序数据时没有问题的原因。 To fix this call FirebaseAuth.getCurrentUser().reload() when your app starts. 要修复此问题,请在应用启动时调用FirebaseAuth.getCurrentUser().reload()

mAuth=FirebaseAuth.getInstance();
user=mAuth.getCurrentUser();
user.reload()
if(!user.isEmailVerified()){
     startActivity(new Intent(HomePage.this,VerifyEmail.class));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM