Reputation: 25
I am currently using Firebase auth ui for signing in my users. What I want to achieve is to let only those users login who have created their account already. I want Firebase auth ui to disable account sign-up whenever new credentials try to log in. Please tell me how to achieve this.
This is how I sign in my users:
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();
}
Thanks in advance.
Upvotes: 2
Views: 1730
Reputation: 138899
What I want to achieve is to let only those users login who have created their account already.
It's the same thing if you want to check if a user is new. So to solve this, you can simply call AdditionalUserInfo's interface isNewUser() method:
Returns whether the user is new or existing
So please use the following lines of code:
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
}
}
});
Upvotes: 1