【问题标题】:View only certain collections by user on Firebase/Firestore仅在 Firebase/Firestore 上按用户查看某些集合
【发布时间】:2019-09-19 13:57:17
【问题描述】:

如何在 Firebase/Firestore 中让每个用户只能看到他的收藏。 我认为通过在集合名称中使用 user_id 来工作,但这是一种安全的方法吗?存储也是如此。 我没有找到 Google 提供的任何机制。

谢谢

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-security


    【解决方案1】:

    您可以使用这样的安全规则

    `service cloud.firestore {
      match /databases/{database}/documents {
        // Make sure the uid of the requesting user matches name of the user
        // document. The wildcard expression {userId} makes the userId variable
        // available in rules.
        match /users/{userId} {
          allow read, update, delete: if request.auth.uid == userId;
          allow create: if request.auth.uid != null;
        }
      }
    }`
    

    您可以在此链接中找到更多信息

    https://firebase.google.com/docs/firestore/security/rules-conditions

    【讨论】:

      猜你喜欢
      • 2020-11-21
      • 1970-01-01
      • 2021-06-30
      • 1970-01-01
      • 2019-04-11
      • 2020-10-13
      • 2018-05-31
      • 1970-01-01
      • 2020-10-10
      相关资源
      最近更新 更多