Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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_Google Cloud Firestore - Fatal编程技术网

Firebase Firestore在查询时缺少权限

Firebase Firestore在查询时缺少权限,firebase,google-cloud-firestore,Firebase,Google Cloud Firestore,我只允许经过身份验证的用户访问他们拥有的内容。 下面是我正在使用的firestore规则 rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /users/{userId}/{documents=**} { allow read, write: if request.auth.uid == userId } } } 这是通过用

我只允许经过身份验证的用户访问他们拥有的内容。 下面是我正在使用的firestore规则

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId}/{documents=**} {
      allow read, write: if request.auth.uid == userId
    }
  }
}
这是通过用户名获取用户配置文件的查询

  const document = await Firebase.firestore().collection('users').where('username', '==', username).get()
  await document.forEach(doc => {
    context.commit('SET_PROFILE', doc.data())
  })
它返回:

FirebaseError: "Missing or insufficient permissions."
但模拟是允许的。我做错了什么


您的规则和查询需要匹配。该规则表示允许使用特定路径,但在查询中,您将获取具有特定用户名的所有用户

只需获取
Firebase.firestore().collection('users').doc(userId.get()