我正试图使用以下文档在Firestore中设置自定义规则:https://firebase.google.com/docs/reference/security/database/#containssubstring
我正在使用自定义声明。
工作原理:
match /calendar/{calendar} {
allow read: if request.auth.token.customData == "calendar-read,calendar-write";
}
什么不起作用,我不知道为什么:
match /calendar/{calendar} {
allow read: if request.auth.token.customData.contains("calendar-read");
}
这将给我:;FirebaseError:缺少或权限不足">
由于您使用的是Firestore,因此应使用Firestore字符串的API文档,而不是实时数据库字符串。您将看到,不存在名为"的方法;包含";Firestore字符串。
如果要检查字符串中是否包含子字符串,则应使用matches((,并提供一个正则表达式进行匹配。
allow read: if request.auth.token.customData.matches(".*calendar-read.*");
如果CCD_ 1包含字符串"0";日历读取";
如果您使用逗号分隔的值列表,请考虑使用split((和list.hasAny((来更清楚。