Firebase中的受保护内容可能? [英] Protected content in Firebase possible?

查看:95
本文介绍了Firebase中的受保护内容可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一种方法来模拟Firebase中的以下数据,我不确定是否有可能。



假设我有一个列表的职位。其中一些我想标记为私人,其中作者指定他们的朋友列表的成员可以查看它。这是否可能,如果是这样的话,可以不分别定义职位和私人职位。

解决方案

您可以使用安全规则。例如,如果我有这个数据集:

  {
users:{
me :{
friends{jack,mary}
},
},
posts:{
post1:{
owner:me,
...
}
}
}

我可以使用如下安全规则:

  {
posts:{
$ post_id:{
//任何朋友都可以阅读我的帖子
.read:auth.uid === data.child('owner ').val()|| root.child('users /'+ data.child.owner.val()+'/ friends /'+ auth.uid).exists(),
// only我可以写出
.write:auth.uid === data.child('owner')。val()
}
}
}

请记住,安全规则不能用作过滤器。您不能迭代帖子列表,只希望找回朋友可以看到的列表 - 如果它遇到列表中不可读的项目,则操作将无法返回结果。


I'm trying to figure out a way to model the following data in Firebase, and I'm not sure if it's possible.

Say I have a list of posts. Some of those I want to flag as private, where the author specifies members of their friends list can view it. Is this possible, and if so is it possible without defining posts and private posts separately.

解决方案

You can specify which posts may be read and written using security rules. For example, if I have this data set:

{
   "users": {
      "me": {
          "friends" { "jack", "mary" }
      },
   },
   "posts": {
       "post1": {
            "owner": "me",
            ...
       }
   }
}

I could use a security rule like the following:

{
   "posts": {
       "$post_id": {
           // any friend can read my post
           ".read":  "auth.uid === data.child('owner').val() || root.child('users/'+data.child.owner.val()+'/friends/'+auth.uid).exists()",
           // only I can write it
           ".write": "auth.uid === data.child('owner').val()"
       }
   }
}

Keep in mind, however, that security rules can't be used as a filter. You can't iterate a list of posts and only expect to get back the ones friends are allowed to see--if it encounters items in the list that aren't readable, then the operation will fail to return results.

这篇关于Firebase中的受保护内容可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆