我的数据库具有以下结构:
users
User_ddac15a6-1890-43d8-9bfb-a13e9b99499e
...
用户的文件夹格式为'User _'+ $ user_id
我正在尝试设置如下规则:
{
"rules": {
"users": {
"User_$user_id": {
// grants write access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".read": "$user_id === auth.uid",
".write": "$user_id === auth.uid"
}
}
}
}
但是当我试图保存规则时,我得到了:
9:7: Key names can't contain ".", "#", "$", "/", "[", or "]" (unbound names start with "$")
如何在这样的文件夹名称结构上设置安全规则?
答案 0 :(得分:2)
您不能将$符号放在规则名称的中间,它必须在开头。但是你可以得到这样的结果:
{
"rules": {
"users": {
"$user_id": {
// grants write access to the owner of this user account
// whose uid must exactly match the key ($user_id)
".read": "$user_id === ('User_'+auth.uid)",
".write": "$user_id === ('User_'+auth.uid)"
}
}
}
}