适用于公共和私人收藏的Firebase Firestore安全规则

时间:2018-10-04 08:06:02

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

我有2个收藏集subscribersposts。我已将安全规则设置为read: write when authenticated。但是我需要subscribers集合来编写未经身份验证的数据,并且需要posts集合来检查身份验证,然后编写如何实现此目标?

2 个答案:

答案 0 :(得分:1)

设置Firestore规则,您也可以在Firebase模拟器中对其进行测试。

service cloud.firestore {
  match /databases/{database}/documents {
    match /subscribers/{document=**} {
      allow read, write : if true;
    }
    match /posts/{document=**} {
      allow read : if true;
      allow write: if request.auth.uid != null;
    }
  }
}

答案非常特定于您要提问的单词,即您经过posts集合身份验证后想要写入数据。我认为读取数据仍然向所有人开放。

答案 1 :(得分:0)

类似的事情应该做到-

service cloud.firestore {
  match /databases/{database}/documents {
    match /subscribers/{document=**} {
      allow read, write;
    }
    match /posts/{document=**} {
      allow read, write: if request.auth.uid != null;
    }
  }
}
相关问题