我目前正在使用 Firebase auth ui 登录我的用户。我想要实现的是只让那些已经创建了帐户的用户登录。 我希望 Firebase auth ui 在新凭据尝试登录时禁用帐户注册。请告诉我如何实现这一点。
这是我登录用户的方式:
if(FirebaseAuth.getInstance().getCurrentUser()==null) {
List<AuthUI.IdpConfig> idpConfigList = Arrays.asList(
//new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.PhoneBuilder().build()
);
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder()
.setAvailableProviders(idpConfigList).build(), SIGN_IN_CONST);
}else {
currentUser=FirebaseAuth.getInstance().getCurrentUser();
onSignedIn();
}
提前致谢。
最佳答案
What I want to achieve is to let only those users login who have created their account already.
如果你想检查一个用户是否是新用户,也是一样的。所以要解决这个问题,你可以简单地调用 AdditionalUserInfo的界面 isNewUser()方法:
Returns whether the user is new or existing
所以请使用下面的代码行:
mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
boolean isNewUser = task.getResult().getAdditionalUserInfo().isNewUser();
if (isNewUser) {
Log.d(TAG, "Is New User!"); //Restrict the authentication process
} else {
Log.d(TAG, "Is Old User!"); //Allow user to authenticate
}
}
});
关于java - Firebase 禁用新用户注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53084905/