有没有办法在 firebase 存储规则中验证用户角色? [英] is there a way to authenticate user role in firebase storage rules?
本文介绍了有没有办法在 firebase 存储规则中验证用户角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试根据用户角色限制 Firebase 存储.
I am trying to restrict firebase storage based on user role.
Database:
users
<uid>
admin=false
... ... ...
我正在尝试在 Firebase 存储中使用以下规则:
I am trying to use the following kind of rule in firebase storage:
root.child('users').child(auth.uid).child('user').child('admin').val() == true
将其添加到写入规则后,我的访问被拒绝.
I am getting access denied after adding this to the write rule.
谢谢.
推荐答案
正如 Frank van Puffelen 在评论中指出的那样:
As Frank van Puffelen pointed out in his comment:
function isAdminUser() {
return request.auth.uid in {
"yaddayadddayaddUserIDKey":"User Name1"
};
}
service firebase.storage {
match /b/<appName>.appspot.com/o {
match /{allPaths=**} {
allow read;
allow write: if request.auth != null && isAdminUser();
}
}
}
这篇关于有没有办法在 firebase 存储规则中验证用户角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文