我正在尝试编写一条规则,允许用户仅访问他有权访问的文档:
match /websites/{website} {
function isSignedIn() {
return request.auth.uid != null;
}
function isAuthorized(rsc) {
return request.auth.token[rsc.data.role] == true
}
function isAdmin() {
return request.auth.token.admin == true
}
allow read, write: if isSignedIn() && (isAuthorized(resource) || isAdmin());
}
似乎request.auth.token[rsc.data.role]
存在问题,但我不知道出了什么问题。 rsc.data.role
在数据库中设置为字符串,而我的用户在令牌中设置为布尔值。
例如:website.role: 'editor'
和request.auth.token.editor: true
。
有什么主意吗?