Firebase禁用新用户注册 [英] Firebase Disable new user signup

查看:88
本文介绍了Firebase禁用新用户注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用Firebase身份验证ui登录用户.我要实现的是仅允许那些已经创建了帐户的用户登录.每当新凭据尝试登录时,我都希望Firebase身份验证ui禁用帐户注册.请告诉我如何实现.

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();
    }

谢谢.

推荐答案

我想要实现的是只允许那些已经创建了帐户的用户登录.

What I want to achieve is to let only those users login who have created their account already.

如果要检查用户是否是新用户,这是同一件事.因此,要解决此问题,您只需调用 AdditionalUserInfo 的界面 isNewUser()方法:

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
        }
    }
});

这篇关于Firebase禁用新用户注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆