我正在使用Xamarin.Firebase.Auth。在我的应用程序的注册活动中,我要检查以确保尚未使用用户名。我需要检查数据库中的用户名。由于这是注册,因此用户尚未通过身份验证,并且无法访问数据库。我允许该应用程序的这一部分进行匿名身份验证。
清除用户名以供使用后,我使用创建新用户,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文档:
https://firebase.google.com/docs/auth/android/anonymous-auth
您需要使用该linkWithCredential
方法而不是“普通” signInWith流。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句