Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 不同Firestore集合的不同安全规则_Firebase_Firebase Authentication_Google Cloud Firestore_Firebase Security - Fatal编程技术网

Firebase 不同Firestore集合的不同安全规则

Firebase 不同Firestore集合的不同安全规则,firebase,firebase-authentication,google-cloud-firestore,firebase-security,Firebase,Firebase Authentication,Google Cloud Firestore,Firebase Security,我目前第一次使用Firestore,并试图稍微了解一下安全规则。我现在的问题非常简单,我可以通过做更多的研究来找出答案,但我想确定我做的是正确的事情,所以我认为在这里提问会更好 如果我在Firestore中有两个集合,一个叫做“A”,另一个叫做“B”,如果我只想让经过身份验证的用户读、写、更新、删除,那么我的安全规则应该是什么。。。在A和B中,每个人都可以阅读,但只有经过身份验证的用户才能写入、更新、删除。。。在B 编辑: 以下是当前规则—它们将B的规则应用于所有集合: service clou

我目前第一次使用Firestore,并试图稍微了解一下安全规则。我现在的问题非常简单,我可以通过做更多的研究来找出答案,但我想确定我做的是正确的事情,所以我认为在这里提问会更好

如果我在Firestore中有两个集合,一个叫做“A”,另一个叫做“B”,如果我只想让经过身份验证的用户读、写、更新、删除,那么我的安全规则应该是什么。。。在A和B中,每个人都可以阅读,但只有经过身份验证的用户才能写入、更新、删除。。。在B

编辑: 以下是当前规则—它们将B的规则应用于所有集合:

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

如果您查看,您会发现以下规则:

针对您的用例进行了修改,如下所示:

service cloud.firestore {
  match /databases/{database}/documents {
    match /A/{id} {
      allow read, write: if request.auth.uid != null;
    }
    match /B/{id} {
      allow read;
      allow write: if request.auth.uid != null;
    }
  }
}
如果您查看,您将发现以下规则:

针对您的用例进行了修改,如下所示:

service cloud.firestore {
  match /databases/{database}/documents {
    match /A/{id} {
      allow read, write: if request.auth.uid != null;
    }
    match /B/{id} {
      allow read;
      allow write: if request.auth.uid != null;
    }
  }
}

请将Firestore规则放在线程中。(我现在在手机上,从这里直接读起来很容易),我会尽力帮你的下面是如何构建它的。使用类似这样的“match/{}”命令:match/{B}请将Firestore规则放入线程中。(我现在在手机上,从这里直接读起来很容易),我会尽力帮你的下面是如何构建它的。使用类似这样的“match/{}”命令:match/{B}