Firebase 限制对所有者的访问
Firebase restrict access to owner
假设我正在使用 firebase 创建一个博客,有多个 authors
每个都在写自己的 posts
。
因此有一个 posts
集合和一个 authors
集合,其规则如下:
- 如果经过身份验证,作者可以创建 post
- 作者可以互相阅读 post 如果经过身份验证
- 作者只能编辑自己的 posts
我有两个问题,第一,我应该使用哪种数据库模式?
- 一个
authors
集合和一个单独的 posts
集合
- 一个
authors
集合,每个作者嵌入 posts
其次,我应该使用哪个安全规则?
{
"rules": {
".read": true,
".write": true
}
// to complete ..
}
首先:您可以使用 ng-show、ng-hide 但这不是最佳解决方案。下面是关于 DoubleClick Campaign Manager 如何处理用户身份验证的 link。 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
假设我正在使用 firebase 创建一个博客,有多个 authors
每个都在写自己的 posts
。
因此有一个 posts
集合和一个 authors
集合,其规则如下:
- 如果经过身份验证,作者可以创建 post
- 作者可以互相阅读 post 如果经过身份验证
- 作者只能编辑自己的 posts
我有两个问题,第一,我应该使用哪种数据库模式?
- 一个
authors
集合和一个单独的posts
集合 - 一个
authors
集合,每个作者嵌入posts
其次,我应该使用哪个安全规则?
{
"rules": {
".read": true,
".write": true
}
// to complete ..
}
首先:您可以使用 ng-show、ng-hide 但这不是最佳解决方案。下面是关于 DoubleClick Campaign Manager 如何处理用户身份验证的 link。 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