如何使用 Firebase 实时数据库最多授权 3 个帐户?

How to authorize a maximum of 3 accounts with Firebase Realtime Database?

我发现此代码允许您在设备 ID 上创建帐户:

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个账号?

Now how to make it possible to create a maximum of 3 accounts on the deviceID?

只需检查一下:

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