我正在尝试根据用户角色限制 Firebase 存储。
Database:
users
<uid>
admin=false
... ... ...
Run Code Online (Sandbox Code Playgroud)
我正在尝试在 firebase 存储中使用以下类型的规则:
root.child('users').child(auth.uid).child('user').child('admin').val() == true
Run Code Online (Sandbox Code Playgroud)
将此添加到写入规则后,我的访问被拒绝。
谢谢。
firebase firebase-security firebase-authentication firebase-realtime-database firebase-storage
是否可以有一个类似于 Firestore 的 get() 函数的 Firebase 存储规则?
基本上我想检查 Firestore 中的用户文档以允许写入存储。
我想处理索赔将是最好的解决方案,但我不确定我可以使用它。
我想要这样的东西:
allow create: if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.canDoSomeStuff == true;
Run Code Online (Sandbox Code Playgroud) firebase firebase-security firebase-storage google-cloud-firestore
我正在尝试根据用户数据保护我的 Firebase(谷歌云存储)文件。在 firestore 中,我使用基于获取数据库内容的规则(在用户表中查找 uid 并匹配一个字段),并且工作正常。我试图在 firebase 存储中使用相同类型的规则,但在模拟器中我得到Error: simulator.rules line [12], column [17]. Function not found error: Name: [get].; Error: Invalid argument provided to call. Function: [get], Argument: ["||invalid_argument||"]. 我的规则是这样的:
match /b/{bucket}/o {
function isAuth() {
return request.auth != null && request.auth.uid != null
}
function isAdmin() {
return isAuth() &&
"admin" in get(/databases/$(database)/documents/users/$(request.auth.uid)).data.roles;
}
function clientMatch(client) { // expects user's "client" field to be ID of client
return isAuth() &&
client == get(/databases/$(database)/documents/users/$(request.auth.uid)).data.client;
}
match /P/Clients/{client}/{allPaths=**} { …Run Code Online (Sandbox Code Playgroud) firebase ×3