我有一些文章。
每篇文章都有一个参考字段到个人资料document撰写该特定文章的作者的姓名。
经过身份验证的用户(使用 Firebase 的身份验证)将与这些配置文件关联。
仅当当前登录的用户拥有该文章时,如何才能使这些文章可由该用户编辑?
在 Firestore 的文档中,有一个反复出现的示例:
service cloud.firestore {
match /databases/{database}/documents {
// Allows you to edit the current user document (like a user's profile).
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
}
// Allows you to read/write messages as long as you're logged in (doesn't matter who you're logged in as, so theoretically you could change other peoples' messages ????).
match /rooms/{roomId} {
match /messages/{messageId} {
allow read, write: if request.auth != null;
}
}
}
}
哪里有关于如何构建和编辑特定用户拥有的文档的示例?
假设您有一份文件,例如owner: <uid>
存储在其中,您可以执行以下操作:
service cloud.firestore {
match /databases/{database}/documents {
match /somecollection/{id} {
allow write: if resource.data.owner == request.auth.uid;
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)