Firestore无效权限:中的request.auth.uid [英] Firestore Invalid Permissions: request.auth.uid in
本文介绍了Firestore无效权限:中的request.auth.uid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Cloud Firestore,但似乎无法让"IN"运算符使用安全规则.我曾尝试使用数组和映射,但均无济于事.当然,当我将其设置为allow read, write;
时,它可以正常工作.我在做什么错了?
I am using Cloud Firestore and I can't seem to get the "IN" operator to work with the security rules. I have tried using array and map but neither work. Of course when I set it to allow read, write;
it works fine. What am I doing wrong?
规则:
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
将返回它的直接子对象而不是它的子子对象(用户和用户2),因此您应该使用get
和exists
而不是
data
will return it's direct children not it's sub-children(users and users2) so you should use get
and exists
instead of 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;
}
签出文档
这篇关于Firestore无效权限:中的request.auth.uid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文