Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用户更改时未激发Firebase身份验证侦听器_Firebase_Xamarin.android_Firebase Authentication - Fatal编程技术网

用户更改时未激发Firebase身份验证侦听器

用户更改时未激发Firebase身份验证侦听器,firebase,xamarin.android,firebase-authentication,Firebase,Xamarin.android,Firebase Authentication,我正在使用。在我的应用程序的注册活动中,我想检查以确保尚未使用用户名。我需要检查数据库中的用户名。由于这是注册,因此用户尚未通过身份验证,并且没有访问数据库的权限。我允许对应用程序的这一部分进行匿名身份验证 清除用户名以供使用后,我使用CreateUserWithEmailAndPasswordAsync创建新用户,完成后需要启动AuthState侦听器。问题是,当用户从匿名更改为创建的用户时,侦听器似乎不会启动 以下是我当前的AuthStateListener: FirebaseAuth.In

我正在使用。在我的应用程序的注册活动中,我想检查以确保尚未使用用户名。我需要检查数据库中的用户名。由于这是注册,因此用户尚未通过身份验证,并且没有访问数据库的权限。我允许对应用程序的这一部分进行匿名身份验证

清除用户名以供使用后,我使用
CreateUserWithEmailAndPasswordAsync
创建新用户,完成后需要启动AuthState侦听器。问题是,当用户从匿名更改为创建的用户时,侦听器似乎不会启动

以下是我当前的AuthStateListener:

FirebaseAuth.Instance.AuthState += (sender, e) =>
        {
            FirebaseUser oUser = e?.Auth?.CurrentUser;

            if (oUser != null && !oUser.IsEmailVerified && !oUser.IsAnonymous)
            {
                //They were successfully created, send the verification email
                if (oUser.SendEmailVerification().IsSuccessful)
                {
                    UserProfileChangeRequest oProfile = new UserProfileChangeRequest.Builder()
                                                    .SetDisplayName(txtName.Text).Build();

                    oUser.UpdateProfile(oProfile);

                    //Add the user information to the database
                    Users oUserToSave = new Users();
                    oUserToSave.displayname = txtName.Text;
                    oUserToSave.email = txtEmail.Text;
                    oUserToSave.prestige = 1;
                    oUserToSave.username = sUsername;


                    //It worked, they need to verify their email address
                    //redirect them to the verification page
                    Intent oVerifyIntent = new Intent(this, typeof(VerificationActivity));
                    StartActivity(oVerifyIntent);
                    FirebaseAuth.Instance.AuthState += null;
                    Finish();
                }
            }
            else if (oUser != null && oUser.IsAnonymous && allowAuthChange)
            {
                //Need to validate their registration
                ValidateRegistration();
            }
        };
如何确保在
CreateUserWithEmailAndPasswordAsync
完成时调用侦听器?Firebase的文档说明在以下情况下应启动侦听器:

  • 就在侦听器注册之后
  • 当用户登录时
  • 当前用户注销时
  • 当当前用户更改时

从匿名用户切换到新创建的用户是否不算作用户更改?

您可以阅读firebase文档:


您需要使用
linkWithCredential
方法,而不是带有flow的“normal”符号。

您阅读过文档吗?据我所知,您需要使用
linkWithCredential
方法,而不是使用
flow的“普通”
登录。是否将此添加为答案?这是一个很好的解决方案,并根据需要启动了AuthState侦听器。