我为我的Firestore数据库编写了规则,只有经过身份验证的用户才能将数据读写到文档中。规则是:
service cloud.firestore {
match /databases/{database}/documents {
// Allow the user to access documents in the "cities" collection
// only if they are authenticated.
match /PhoneAuthUsers/{phoneid=**} {
allow read, write: if request.auth.uid != null;
}
}
}
并且每当我运行该应用程序时,我发布规则
“权限不足”
我的身份验证方法是Phoneauthentication,我在身份验证选项卡中具有身份验证ID。这是我的数据库结构:
**- PhoneAuthUsers(Collection)
- Phonenumber(documents)
- Accounts(Collection)
-autoid(Document)**
客户端代码:
db.collection("PhoneAuthUsers")
.whereEqualTo("PhoneNumber", mobile)
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
System.out.println("hello user");
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
Log.d(TAG, document.getId() + " => " + document.getData());
AuthID = document.getId();
System.out.print("AuthIDPhonenumber" + AuthID);
System.out.println("PhoneNumber");
String phone = document.getString("PhoneNumber");
Log.d(TAG, "onSuccess: " + phone);
if (phone.equals(mobile)) {
count = count + 1;
System.out.println("count" + count);
}
}
尝试执行查询时,它显示缺少足够的权限。 例如 : PhoneAuthUsers / + 911234567890 / Accounts / autoid / Field Values 。从phoneauthusers获取文档时,我缺少足够的权限。如何解决该问题。