我想使用Firebase为安卓开发一个在线密码保存应用。Firebase的文档告诉我有关身份验证和CRUD方法的信息,但我找不到任何有关允许用户创建仅对他们可访问的私人数据的内容。我该如何实现呢?或者在哪里可以找到这些信息?
{
"rules": {
"users": {
"$uid": {
// grants write access to the owner of this user account
// whose uid must exactly match the key ($uid)
".write": "$uid === auth.uid"
}
}
}
}
但我建议阅读完整的文档以获取详细信息。
{
"users" : {
"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" : {
//private data of user with unique id "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
},
"ffffffff-gggg-hhhh-iiii-kkkkkkkkkkkk" : {
//private data of user with unique id "ffffffff-gggg-hhhh-iiii-kkkkkkkkkkkk"
}
}
}
您必须仅允许正确的用户读取和写入文件夹,甚至在路径不存在时创建路径。规则可以如下:
{
"rules": {
"users":{
".write": "newData.hasChild(auth.uid)", //you can write only if you put your data inside a path starting with your id
"$uid":{
".read":"$uid == auth.uid" //only the right user can read the data
}
}
}
}