首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FireStore:权限-在get匹配中被拒绝

FireStore:权限-在get匹配中被拒绝
EN

Stack Overflow用户
提问于 2017-12-24 14:44:08
回答 1查看 721关注 0票数 0

我有下一个firestore规则:

代码语言:javascript
复制
service cloud.firestore {
  match /databases/{database}/documents {
    match /{usuarios=**} {
        allow write: if get(/usuarios/$(request.auth.uid)).data.level == 0 || get(/usuarios/$(request.auth.uid)).level == 0;
    }
  }
}

当我尝试这个查询时,我得到了"permission-denied“:

代码语言:javascript
复制
firebase.firestore().collection('usuarios').doc(uid).set({...});

这实际上是我的数据库:

pd:我想在我的数据库中添加关于新用户的信息(通过他的UID)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-24 16:13:18

这将是非常昂贵和低效的,因为您是按get请求付费的。相反,您应该像定义数据库结构一样编写规则。我的意思是:

代码语言:javascript
复制
service cloud.firestore {
  match /databases/{database}/documents {
    match /usuarios/{uid} {
      // Give write access to any field within the document who's id is the uid
      // Add other validation as needed.
      allow write: if uid == request.auth.uid
          // Give admin access to anyone who's `level == 0`
          // Make sure to add the `databases...` boilerplate
          || get(/databases/$(database)/documents/usuarios/$(request.auth.uid)).data.level == 0;

      // If necessary, give access to sub-collections.
      // (We can't do it for uid or it will become a path object that we can't use as a string.)
      /{sub=**} {
        allow write: if uid == request.auth.uid;
      }
    }
  }
}

如果你想看到完全清除的规则做着非常相似的事情,我有一个open source exemple。干杯!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47958595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档