【问题标题】:How to make groups in firebase authentication using android?如何使用android在firebase身份验证中创建组?
【发布时间】:2019-05-22 13:22:40
【问题描述】:

我有一些关于 firebase 身份验证的问题,是否可以创建群组?例如,我有一个供销售员使用的应用程序和另一个供买家使用的应用程序,我想将身份验证保存在 2 个不同的组中。 我问这个是否有可能我可以让一个火力基地自动做一个不同的凭据提示。

如果密码是这样的,我将创建一个登录;

    mAuth.createUserWithEmailAndPassword(email, senha)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d("TagCerta", "createUserWithEmail:success");
                        FirebaseUser user = mAuth.getCurrentUser();
                        comerciante.setUid(user.getUid());
                        comerciante.salvar();
                        Intent inicio = new Intent(CadastrarActivity.this, ComercianteActivity.class);
                        startActivity(inicio);
                        finish();


                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w("TagErrada", "createUserWithEmail:failure", task.getException());
                        Toast.makeText(CadastrarActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();

                    }

                    // ...
                }
            });

【问题讨论】:

    标签: android firebase firebase-authentication


    【解决方案1】:

    您不能在 firebase 身份验证中执行此操作。为此,您需要使用 firebase 数据库,然后您可以执行以下操作:

    FirebaseUser currentFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("salesman");
    ref.child(currentFirebaseUser.getUid()).child("name").setValue("peter sells ?");
    
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("buyer");
    ref.child(currentFirebaseUser.getUid()).child("name").setValue("peter buys also! ?");
    

    那么您将拥有以下数据库:

    salesman
        userId
            name : peter sells ?
    buyer
       userId
            name : peter buys also! ?
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-11-27
      相关资源
      最近更新 更多