错误域= FIRFirestoreErrorDomain代码= 7“缺少权限或权限不足". [英] Error Domain=FIRFirestoreErrorDomain Code=7 "Missing or insufficient permissions."

查看:49
本文介绍了错误域= FIRFirestoreErrorDomain代码= 7“缺少权限或权限不足".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有以下代码从firestore中检索文档,该函数在我的viewDidLoad()中调用:

So I have the following code retrieving documents from firestore, this function is called in my viewDidLoad():

func loadAnnotations() {
    
    db.collection("jumpSpotAnnotations").getDocuments { (querySnapshot, error) in
        if let error = error {
            print("There was an issue retrieving data from Firestore: \(error)")
            
            let alertController = UIAlertController(title: "Oops!", message: "We are having trouble loading the cliff jumping locations.  Be sure to check your internet connection.", preferredStyle: .alert)
            
            let okayAction = UIAlertAction(title: "Okay", style: .cancel, handler: nil)
            
            alertController.addAction(okayAction)
            
            self.present(alertController, animated: true, completion: nil)
        } else {
            if let snapshotDocuments = querySnapshot?.documents {
                //print(snapshotDocuments)
                for doc in snapshotDocuments {

其余功能并不重要.检索数据时出现错误:Error Domain = FIRFirestoreErrorDomain Code = 7缺少权限或权限不足".当我第一次得到这个信息时,我意识到这是由于自从应用的Firebase项目创建的第一天以来,我还没有更新我的安全规则,并且已经过去了30天,因此Google将无法再访问直到我更新规则.这些是原始规则:

The rest of the function isn't important. I am getting an error when retrieving the data: Error Domain=FIRFirestoreErrorDomain Code=7 "Missing or insufficient permissions." When I first got this, I realized that it was due to the fact that I had not updated my security rules since the first day that the Firebase project for the app was created, and 30 days has passed, so Google wouldn't access anymore until I updated the rules. These are the ORIGINAL rules:

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

就此应用而言,现在我可以很好地与用户创建和读取任何数据.但是,我不希望它们能够修改或删除数据.因此,我在Stack上询问了有关如何执行此操作的问题,并在此处得到了回答:

For the purpose of this app, right now I am fine with user creating and reading any data. I do not, however want them to be able to modify or delete data. So I asked a question here on Stack about how to do that, and was answered here: How to prevent Firestore documents being deleted / modified, but allow all reads and writes So my updated security rules are now:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /collection1/{jumpSpotAnnotations} {
      allow read, create;
    }
  }
}

但是,当我尝试检索数据时,仍然出现完全相同的错误.新的安全规则已经发布.所以我的问题是,在按publish进行正式更新后,我需要做些什么吗,还是让我的模拟器能够检索数据?还是我的安全规则中的代码或Xcode中的函数不正确的问题?为了我想做的.请记住,Xcode中的函数可以与原始规则完美地配合使用(我将规则完全打开时就象刚创建Firestore项目时那样,因此我可以轻松地在模拟器中进行测试).任何帮助深表感谢!

However I am still getting the exact same error when I try to retrieve the data. The new security rules HAVE been published. So my question is, is there something I need to do after pressing publish to update it officially, and have my simulator be able to retrieve the data, OR is the problem that my code in either my security rules or my function in Xcode is incorrect for what I want to do. Keep in mind, the function in Xcode worked perfectly with the original rules (I made the rules completely open like that when I first made the Firestore project so I could just test in the simulator easily). Any help is much appreciated!

推荐答案

在回答上一个问题时,我建议您调出各个集合的名称.您只是拿走了我给的东西,就逐字抄了下来.您需要在规则中使用实际集合的名称:

In my answer to your previous question, I suggested that you call out the names of the individual collections. You just took what I gave and copied it verbatim. You need to use the name of the actual collection in your rule:

    match /jumpSpotAnnotations/{id} {
      allow read, create;
    }

再次,我强烈建议您阅读我链接的文档,以便您可以了解安全规则的工作原理.

Again, I strongly recommend that you read the documentation I linked to so you can learn how security rules work.

这篇关于错误域= FIRFirestoreErrorDomain代码= 7“缺少权限或权限不足".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆