在angular 4+中公开和不公开 [英] Make a public profile and a private profile in angular 4+

查看:47
本文介绍了在angular 4+中公开和不公开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来考虑这个问题,这是我的Firebase模式.

I need help for think this problem, this is my firebase schema.

我需要查看个人资料,但要公开显示,最好的方式是什么?

I need to make a view of the profile but public, how is the best way to make it?

那么,您如何看待架构,以及一个用户如何进行对话?

So, what do you think about the schema and how does one user have conversations?

我认为对话节点可以保留在用户节点之外,并且每个对话都引用给每个用户.选择哪一个?

I think that the conversations node, can stay outside the user node and each referencing conversation to each user. Which one to choose?

推荐答案

您正在将多个数据类型嵌套在单个根目录下,这是大多数Firebase Realtime Database开发人员所建议的.一些最重要的原因是:

You're nesting multi data types under a single root, which is something most Firebase Realtime Database developers recommend against. Some of the most important reasons for this are:

  1. Firebase始终会读取整个节点,因此您必须先读取用户的所有对话,才能读取其属性.在许多情况下,这样做很浪费,例如,当您只想显示用户名列表时.
  2. 一旦授予用户对某个节点的读取访问权限,他们就可以访问该节点下的所有数据.您不能在较低级别取消此权限.这意味着在您的情况下,任何可以阅读用户个人资料信息的人,也可以阅读他们的所有对话.这可能不是您想要的.
  3. 您可以尝试通过授予用户对用户特定属性的读取权限来解决最后一个问题,因此/Users/$uid/name等等,这样他们可以读取名称,但不能读取对话.在单个用户节点上,这确实可以工作.但是使用这种结构,您将无法再获得用户配置文件列表,因为您没有对/Users的读取权限.
  1. Firebase will always read entire nodes, so you cannot read a user's properties without also reading all their conversations. There are many scenarios where this is wasteful, such as when you only want to show a list of user names.
  2. Once you grant a user read access to a node, they have access to all data under that node. You cannot take this permission away at a lower level. This means in your case that anyone who can read a user's profile information, can also read all their conversations. This may not be what you want.
  3. You may try to work around this last concern by giving the user read permission to the specific property of the users, so /Users/$uid/name, etc. that way they can read the names, but not the conversations. On a individual user node this will indeed work. But with this structure you cannot get a list of user profiles anymore, since you don't have read permission on /Users.

为共享内容建模的常用方法是将对话和用户个人资料分成单独的顶层节点,每个节点都键入用户的UID:

The common way to model what you shared is to split the conversations and the user profiles into separate top-level nodes, each keyed on the user's UID:

Users
  $uid
    name: "Matias Celiz"
    gender: "..."
Conversations
  $uid
    ...

如果您想要单独的公共配置文件信息和私有配置文件信息,请添加另一个顶级节点以将两者分开:

If you want separate public profile information and private profile information, add another top-level node to split the two:

Users
  $uid
    name: "Matias Celiz"
    gender: "..."
Profiles
  $uid
    name: "Matias Celiz"
Conversations
  $uid
    ...

这篇关于在angular 4+中公开和不公开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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