我正在使用 Cloud Firestore,但似乎无法让“IN”运算符使用安全规则。我试过使用数组和 map ,但都不起作用。当然,当我将它设置为 allow read, write;
时它工作正常。我究竟做错了什么?
规则:
service cloud.firestore {
match /databases/{database}/documents {
match /rooms/{roomId=**} {
allow read, write: if request.auth.uid in resource.data.users;
allow read, write: if request.auth.uid in resource.data.users2;
allow create: if request.auth != null;
}
match /user-rooms/{userId} {
allow read, write: if userId == request.auth.uid;
}
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
allow get, create: if request.auth != null;
}
}
}
客户:
db.collection("rooms")
.document(self.room.getRoomId())
.collection("messages")
.addSnapshotListener { .....
//Room is: d6l946swspNSouANzVdZ
//Username is: eX8gkxJNDREv
最佳答案
data
将返回它的直接 child 而不是它的子 child (用户和用户2)所以你应该使用 get
和 exists
而不是 in
match /rooms/{roomId=**} {
allow read, write: if request.auth.uid in get(/databases/$(database)/documents/rooms/$(roomId)/users/$(request.auth.uid)).data;
allow read, write: if exists(/databases/$(database)/documents/rooms/$(roomId)/users2/$(request.auth.uid));
allow create: if request.auth != null;
}
结帐 doc
关于firebase - Firestore 无效权限 : request. auth.uid in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48496288/