gpt4 book ai didi

javascript - Firebase 限制对所有者的访问

转载 作者:行者123 更新时间:2023-11-30 12:24:58 25 4
gpt4 key购买 nike

假设我正在使用 firebase 创建一个博客,有多个作者,每个人都在写他们自己的帖子

因此有一个 posts 集合和一个 authors 集合,其规则如下:

  • 如果经过身份验证,作者可以创建帖子
  • 如果经过身份验证,作者可以阅读彼此的帖子
  • 作者只能编辑自己的帖子

我有两个问题,第一,我应该使用哪种数据库模式?

  • 一个authors 集合和一个单独的posts 集合
  • 一个 authors 集合,每个作者都嵌入了 posts

其次,我应该使用哪种安全规则?

{
"rules": {
".read": true,
".write": true
}
// to complete ..
}

最佳答案

首先:您可以使用 ng-show、ng-hide 但这不是最佳解决方案。这是 DoubleClick Campaign Manager 如何处理用户身份验证的链接。 https://docs.google.com/file/d/0B4F6Csor-S1cNThqekp4NUZCSmc/edit

其次:您可以按照这种方式编写规则 - 在下方,根据需要更改值。

{
"rules": {
"products": {
".read": true,
".write": true
},
"sectest": {
".read": true,
".write": "(newData.child('admin').child(auth.uid).exists()) ||
(data.exists() && data.child('admin').child(auth.uid).val() == auth.uid) ||
(root.child('users/'+auth.uid+'/isadmin').exists())"
},
"users": {
".write": true,
"$uid": {
".read": "auth != null && auth.uid == $uid"
}
},
"venders": {
".read": true,
".write": true
},
"channels": {
".read": true,
".write": true
}
}
}

查看这个 Angular 博客示例:https://github.com/yearofmoo/hexo-angular-blog-example

关于javascript - Firebase 限制对所有者的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29731235/

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