我得到了错误
gettingdocuments.com.google.firebase.firestore.FirebaseFirestoreException:
PERMISSION_DENIED:缺少或权限不足。
对于下面关于else语句的代码
db.collection("users")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
s(document.getId() + " => " + document.getData());
}
} else {
s("Error getting documents."+ task.getException());
}
}
});
在指定安全规则后,我还出现了“缺少或权限不足”错误。事实证明,默认情况下规则不是递归的!例如,如果你写了一个规则
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
该规则将不适用于/users/{userId}下的任何子集合。这就是我犯错误的原因。
我通过指定规则来修复它:
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
在文档的相关部分中阅读更多信息。
在指定安全规则后,我还出现了“缺少或权限不足”错误。事实证明,默认情况下规则不是递归的!例如,如果你写了一个规则
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
该规则将不适用于/users/{userId}下的任何子集合。这就是我犯错误的原因。
我通过指定规则来修复它:
match /users/{userId}/{document=**} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
在文档的相关部分中阅读更多信息。
时间限制可能已过
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// This rule allows anyone on the internet to view, edit, and delete
// all data in your Firestore database. It is useful for getting
// started, but it is configured to expire after 30 days because it
// leaves your app open to attackers. At that time, all client
// requests to your Firestore database will be denied.
//
// Make sure to write security rules for your app before that time, or else
// your app will lose access to your Firestore database
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020,7, 1);
}
}
}
这一行更改了日期:
allow read, write: if request.time < timestamp.date(2020,7, 1);