阻止访客用户在Firebase

时间:2018-01-26 20:41:49

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

我有一个类似Instagram的应用程序。我想实现访客用户身份验证,因此人们无需注册即可查看其他人的照片。

但我还需要为访客用户禁用所有写入数据库功能。我怎样才能做到这一点?

假设我有这个默认的安全规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

我知道我不应该在现实生活中这样做。仅举例来说。

1 个答案:

答案 0 :(得分:0)

您所询问的内容几乎直接针对in the docs,但它看起来像是:

compare:

只要service cloud.firestore { match /databases/{database}/documents { // Make sure the uid of the requesting user matches the 'author_id' field // of the document match /photos/{photoId} { allow read: if true; allow create: if request.auth.uid != null && request.data.uid == request.auth.uid; } } } 字段与自己经过身份验证的uid匹配,这将允许任何经过身份验证的用户创建照片,但允许任何人(已登录或未登录)读取{中的数据{1}}收集。