以 angular 4+ 制作公开资料和私人资料 [英] Make a public profile and a private profile in angular 4+

查看:22
本文介绍了以 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 实时数据库开发人员所反对的.造成这种情况的一些最重要的原因是:

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天全站免登陆