【问题标题】:How to authorize a maximum of 3 accounts with Firebase Realtime Database?如何使用 Firebase 实时数据库授权最多 3 个帐户?
【发布时间】:2021-12-23 18:43:44
【问题描述】:

我发现这段代码可以让你在 deviceID 上创建一个帐户:

private void queryAccountExistence(final String email,final String password) {

     DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users");

     Query query = ref.orderByChild("deviceID").equalTo(deviceID);

     query.addListenerForSingleValueEvent(new ValueEventListener() {
     @Override
     public void onDataChange(@NonNull DataSnapshot snapshot) {

     if (snapshot.exists()) {
     //la device est déjà enregistré
     Toast.makeText(RegisterActivity.this,
     "Cette device est déjà lié à un compte, connectez-vous",
     Toast.LENGTH_SHORT).show();

     } else {
     //Aucune deviceID trouvé
     createAccount(email, pass);

     }

     }

     @Override
     public void onCancelled(@NonNull DatabaseError error) {

     }
     });
}

现在如何才能在 deviceID 上创建最多 3 个帐户?

【问题讨论】:

    标签: java android firebase firebase-realtime-database


    【解决方案1】:

    现在如何才能在 deviceID 上创建最多 3 个帐户?

    只需检查:

    if (snapshot.exists()) {
        if (snapshot.getChildrenCount() <= 3) {
            createAccount(email, pass);
        } else {
            Log.d("TAG", "You reached the maximum limit of three account per deviceID.");
        }
    }
    

    【讨论】:

    • 我放了,非常感谢!
    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    相关资源
    最近更新 更多