【发布时间】:2020-02-20 10:35:14
【问题描述】:
我的网站有多个具有不同权限的帐户。
我在 Firestore 令牌中使用自定义声明来授予用户正确的访问权限。
到目前为止,它与此设置完美配合:
有权访问 1 个位置的用户 1 的声明如下所示:{"companyLocation": "testLocation1"}
很快我将拥有可以访问一个或多个位置的用户。例如,用户 2 可以访问“testLocation2”和“testLocation3”,而无需访问“testLocation1”。
例如,用户 2 声明可以有一个分隔符(“¤”),看起来像这样:{"companyLocation": "testLocation2 ¤ testLocation3"}
如何通过安全规则实现这一点?我试过了:
function checkMultipleLocations(){
return request.auth.token.companyLocation.contains('testLocation2');
}
这给了我一个错误说明:
无效的函数名:包含
在文档中它声明您可以使用in: v in x(检查值 v 是否在列表 x 中),但这不适用于列表(不返回 true),仅适用于对象/地图(尝试通过拆分用户将字符串声明为数组,没有运气)。
有什么想法吗?
【问题讨论】:
标签: google-cloud-firestore firebase-security