gpt4 book ai didi

firebase - Firestore 无效权限 : request. auth.uid in

转载 作者:行者123 更新时间:2023-12-04 03:01:50 25 4
gpt4 key购买 nike

我正在使用 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

enter image description here

最佳答案

data将返回它的直接 child 而不是它的子 child (用户和用户2)所以你应该使用 getexists而不是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com