admin管理员组文章数量:1316393
I'm building a webapp where users can create rooms and join rooms of others. My goal is for users to be able to retrieve any room they have the ID of, but only list rooms they are already a member of. (uid in room.participant_uids)
My firestore.rules so far succeed in restricting access based on participant.ids:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /users/{uid} {
allow read: if request.auth.uid == uid;
}
match /rooms/{id} {
allow read: if request.auth.uid in resource.data.participant_uids;
}
}
}
However I would like another rule that allows reading of a document only when retrieving a single document by id.
I can solve this with a Firebase function if it is not possible, but I'd like to do without.
I'm building a webapp where users can create rooms and join rooms of others. My goal is for users to be able to retrieve any room they have the ID of, but only list rooms they are already a member of. (uid in room.participant_uids)
My firestore.rules so far succeed in restricting access based on participant.ids:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
match /users/{uid} {
allow read: if request.auth.uid == uid;
}
match /rooms/{id} {
allow read: if request.auth.uid in resource.data.participant_uids;
}
}
}
However I would like another rule that allows reading of a document only when retrieving a single document by id.
I can solve this with a Firebase function if it is not possible, but I'd like to do without.
Share Improve this question edited Jan 29 at 11:53 Daniel Eisenhardt asked Jan 29 at 10:26 Daniel EisenhardtDaniel Eisenhardt 5936 silver badges14 bronze badges 1 |1 Answer
Reset to default 1You can use get
to specify a rule that applies to single document access. If you want anyone (authenticated or not) to be able to get a single "rooms" document:
match /rooms/{id} {
allow get: true;
allow read: if request.auth.uid in resource.data.participant_uids;
}
You may want to require authentication or some other requirements.
See the documentation for granular access for more details.
本文标签: firebase securityfirestorerules allow read of single document onlyStack Overflow
版权声明:本文标题:firebase security - firestore.rules allow read of single document only - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742003050a2411402.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
allow list: if request.auth.uid in resource.data.participant_uids;
This rule restricts listing rooms to only those where the user is a participant. The list operation is used when querying a collection, which is mentioned in the Documentation. – Sandeep Vokkareni Commented Jan 29 at 12:19