flutter - firestore 邮政限制
问题描述
我设法在应用程序中使用了firestore。用户可以发布一个博客,该博客将实时更新给所有用户。我想限制用户只能从他们的帐户发布一个博客。我怎样才能做到这一点?如何限制用户发布多个帖子?
解决方案
您可以使用 Firestore 规则
service cloud.firestore {
match /databases/{database}/documents {
match /blogs/{blogId} {
allow create:
if request.auth.uid == resource.data.userAuthId &&
request.resource.data.authorNumOfBlogs == 0
allow update, delete:
if request.auth.uid == resource.data.userAuthId
}
}
}
如果请求与当前用户 id 匹配并且该用户只有一篇博客文章,这将只允许用户创建博客。
确保authorNumOfBlogs
在您的/blogs
集合中创建一个字段,并在用户创建/删除博客文章时相应地增加/减少它。此外,如果您尚未在 firestore 中跟踪用户的 uid,请在您的集合中添加一个userAuthId
字段。/users
推荐阅读
- javascript - 如何在 Node.js 中找到我的浏览器的操作系统、架构类型等详细信息?
- ios - 应用因应用内购买而被拒绝
- linux-kernel - .config 和 kconfig 之间的区别
- node.js - 反应中的标签不显示适当的内容
- java - 尽管用户名和密码正确,但登录表单会抛出无效的用户名或密码
- ruby-on-rails - AWS Beanstalk - nginx 强制 SSL 配置更改后,Worker env 不处理后台作业
- google-sheets - 正常运行时脚本失败,但调试正常
- javascript - moment-timezone.js:476 Moment Timezone 没有亚洲/耶路撒冷的数据
- java - 控制器的弹簧启动基本路径,但不是应用程序上下文
- c# - 无法在 C# 中反序列化 JSON 响应