Firebase 用户安全模拟
Firebase User Security Simulation
我真的在这里摸不着头脑,而且我已经尽可能多地阅读了许多其他案例。我是 Firebase 的新手,但对它有所了解。我想将数据库的某些记录限制为某些用户。所以这是我的 JSON:
"accounts" : {
"13asdf313" : {
"dog" : "bacon",
"email" : "luis@fakeemail.com",
"first" : "luis",
"last" : "xxxx"
},
"HlELrrGDbiMKgxxxx" : {
"name" : "Luis"
},
"anthony" : {
"email" : "anthony@fakeemail.com",
"last" : "xxxx",
"name" : "anthony"
},
"jpSq6UzX0mcAvExxxx" : {
"name" : "anthony"
}
}
以下是根据我阅读的内容制定的规则:
{
"rules": {
"accounts":{
"$uid":{
".read": "auth.uid == $uid",
".write": "auth.uid == $uid"
}
},
}
}
在模拟器中,我使用了底部条件(我什至把 /accounts 放在位置字段中)。我使用了 UID:HlELrrGDbiMKgxxxx,直接从 Firebase 帐户列表中复制。
这总是失败
我做错了什么?
您必须在 位置 字段中插入 accounts/HlELrrGDbiMKgxxxx
。
否则您正在尝试访问 整个 数据库(标准位置是 root,它覆盖了整个数据库)。您的规则只是为子 accounts/$uid
设置的,要访问它,身份验证中的用户 ID 和数据库中的子位置必须匹配。
我真的在这里摸不着头脑,而且我已经尽可能多地阅读了许多其他案例。我是 Firebase 的新手,但对它有所了解。我想将数据库的某些记录限制为某些用户。所以这是我的 JSON:
"accounts" : {
"13asdf313" : {
"dog" : "bacon",
"email" : "luis@fakeemail.com",
"first" : "luis",
"last" : "xxxx"
},
"HlELrrGDbiMKgxxxx" : {
"name" : "Luis"
},
"anthony" : {
"email" : "anthony@fakeemail.com",
"last" : "xxxx",
"name" : "anthony"
},
"jpSq6UzX0mcAvExxxx" : {
"name" : "anthony"
}
}
以下是根据我阅读的内容制定的规则:
{
"rules": {
"accounts":{
"$uid":{
".read": "auth.uid == $uid",
".write": "auth.uid == $uid"
}
},
}
}
在模拟器中,我使用了底部条件(我什至把 /accounts 放在位置字段中)。我使用了 UID:HlELrrGDbiMKgxxxx,直接从 Firebase 帐户列表中复制。
这总是失败
我做错了什么?
您必须在 位置 字段中插入 accounts/HlELrrGDbiMKgxxxx
。
否则您正在尝试访问 整个 数据库(标准位置是 root,它覆盖了整个数据库)。您的规则只是为子 accounts/$uid
设置的,要访问它,身份验证中的用户 ID 和数据库中的子位置必须匹配。