Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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安全规则中使用通配符_Firebase_Google Cloud Firestore_Firebase Security - Fatal编程技术网

如何在firebase安全规则中使用通配符

如何在firebase安全规则中使用通配符,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,我试图在我的firebase安全规则中使用通配符,但它不能像在线文档所描述的那样工作 我想返回整个行程列表集合,但安全规则不起作用 match /itinerary/{userId=**}/itineraryList/{doc} { allow read: if request.auth.uid == userId; allow write: if request.auth.uid == userId; } 允许经过身份验证的用户访问整个列表的正确语法是什么?根据您的评论更新: 如果

我试图在我的firebase安全规则中使用通配符,但它不能像在线文档所描述的那样工作

我想返回整个行程列表集合,但安全规则不起作用

match /itinerary/{userId=**}/itineraryList/{doc} {
  allow read: if request.auth.uid == userId; 
  allow write: if request.auth.uid == userId;
}

允许经过身份验证的用户访问整个列表的正确语法是什么?

根据您的评论更新:

如果要向任何经过身份验证的用户授予对
行程
集合(包括子集合)下所有文档的读取权限,请执行以下操作:

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

      //possibly add another rule for write

  }
}

初始答案:

这是因为通过执行
{userId=**}
您使用的是“递归通配符语法”,请参阅。它将对应于“整个匹配路径段”

你应该做:

service cloud.firestore {
  match /databases/{database}/documents {
      match /itinerary/{userId}/itineraryList/{doc} {
        allow read: if request.auth.uid == userId; 
        allow write: if request.auth.uid == userId;
      }  
  }
}

您也可以观看有关Firestore安全规则的Firebase官方视频,其中解释了这一点:

更新您的评论:

如果要向任何经过身份验证的用户授予对
行程
集合(包括子集合)下所有文档的读取权限,请执行以下操作:

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

      //possibly add another rule for write

  }
}

初始答案:

这是因为通过执行
{userId=**}
您使用的是“递归通配符语法”,请参阅。它将对应于“整个匹配路径段”

你应该做:

service cloud.firestore {
  match /databases/{database}/documents {
      match /itinerary/{userId}/itineraryList/{doc} {
        allow read: if request.auth.uid == userId; 
        allow write: if request.auth.uid == userId;
      }  
  }
}

您还可以观看有关Firestore安全规则的Firebase官方视频,其中解释了这一点:

这只会为我提供与请求用户ID匹配的用户ID文档。但我需要用户的完整列表…不仅仅是在用户ID字段与请求的用户ID匹配时。即使{userId}=userIdSo您想要的是任何经过身份验证的用户都能够读取和写入
行程
集合(包括子集合)下的所有文档?我的理解正确吗?是的。但只允许读取权限…我不想给它们写入权限。这是我的集合引用,是提供引用的服务,如果(用户){This.allItineraries=firebase.firestore().collection(
inventary
);}/inventary/{userId=**}这样做的目的是试图给我/internative/userId下的所有内容…但是userId中没有文档。我需要/itineray/userId/itineraylist/中的文档。这只会为我提供与请求用户ID匹配的用户ID的文档。但我需要用户的整个列表…而不仅仅是在用户ID字段与请求的用户ID匹配时。即使{userId}=userIdSo您想要的是任何经过身份验证的用户都能够读取和写入
行程
集合(包括子集合)下的所有文档?我的理解正确吗?是的。但只允许读取权限…我不想给它们写入权限。这是我的集合引用,是提供引用的服务,如果(用户){This.allItineraries=firebase.firestore().collection(
inventary
);}/inventary/{userId=**}这样做的目的是试图给我/internative/userId下的所有内容…但是userId中没有文档。我需要/inventary/userId/inventurelist中的文档/