我通过使用云功能添加到令牌来阻止用户
exports.blockUser = functions.https.onCall(async(data, context) => {
const user = await admin.auth().getUserByEmail(data['email']);
if(context.auth.token.admin){
admin.auth().setCustomUserClaims(user.uid, {
block: true
});
console.log(data['email'] + " has been blocked");
return 1;
}else{
return 2;
}});
在我的规则中,我设置允许读取if = = null,因为未被阻止的用户将不会在其令牌上拥有该数据。
allow read: if request.auth.token.block == null;
但是这不起作用,许可被拒绝。
我已尝试反过来确保令牌数据存在
allow read: if request.auth.token.block == true;
这允许仅阻止用户能够读取数据。它的工作原理。这意味着令牌上的数据没有问题。
我该怎么做才能让那些在其令牌上没有“block”属性的用户能够读取数据?
对于安全规则,缺少的属性与等于null的属性不同。您应该检查块属性是否确实存在,并检查其值是否应该限制访问
allow read: if !("block" in request.auth.token) || equest.auth.token.block == false;
参考Map的文档(request.auth.token
是一张地图)。