如何在firebase中阻止读取孩子的特定字段 [英] How to block reading specific field in child in the firebase

查看:58
本文介绍了如何在firebase中阻止读取孩子的特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有用户名,UID,电子邮件的用户所以我希望无法到达电子邮件字段和UID,因为某些用户不想通过阅读其电子邮件子级来向其发送电子邮件,并且在我的应用程序中注册以搜索用户不是必需的如何解决这个问题?

I have User which has a username, UID, email so I want the email field and UID cant reached because some users don't want to spam their email by reading its email child and in my app register to search Users is not required How can work with this problem?

我想制造一棵树,除了Firebase以外,其他任何人都不能读/写,但是Firebase中不存在

I thought to make a tree that no one can read/write except the Firebase but it doesn't exist in the Firebase

编辑

{
  "bdjsjd" : {
    "email" : "something1@gmail.com",
    "name" : "bdbsndnd",
    "username" : "bdjsjd"
  },
  "developer" : {
    "email" : "something2@gmail.com",
    "name" : "dev_mohammed",
    "username" : "developer"
  }
}

当我想通过键(键是用户的用户名)读取它时,它也会返回电子邮件,但是如果用户不想从其他人那里收到电子邮件,我想返回除电子邮件字段以外的所有内容但是我可以这样做吗?

when I want to read this by key(the key is user's username)it will return the email as well but I want to return everything except the email field if the user doesn't want to get the email by anyone else him but can I do this?

推荐答案

Firebase将始终返回完整的节点.因此,您可以允许读取每个用户的 email name 节点,而不是 username .但是,如果允许读取用户节点(更高一级),则无法从结果中排除 username .

Firebase will always returns complete nodes. So you can allow reading of each user's email and name nodes, and not of username. But if you allow reading of the user node (one level higher), there is no way to then exclude the username from the results.

为确保这种结构的安全,您需要将用户名与其他详细信息放在不同的顶级节点中.像这样:

To allow securing such a structure, you'll need to put the usernames in a different top-level node from the other details. Something like:

"profiles": {
  "bdjsjd" : {
    "email" : "something1@gmail.com",
    "name" : "bdbsndnd"
  },
  "developer" : {
    "email" : "something2@gmail.com",
    "name" : "dev_mohammed"
  }
},
"user_names": {
  "bdjsjd": "bdjsjd",
  "developer" : "developer"
}

现在,您可以对/profiles /user_names 赋予不同的权限.

Now you can give different permissions on /profiles and on /user_names.

另请参阅:

这篇关于如何在firebase中阻止读取孩子的特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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