我正在使用firebase构建一个Android应用程序 . 简单用户将登录并向数据库添加数据 . 用户只能看到自己的数据 . 然后我需要一个管理员帐户来查看firebase数据库中的所有数据 . 我该怎么办呢?
你有没有以任何方式保护你的数据库?如果没有,我建议开始使用documentation for Firebase security rules .
我通常将我的数据库保护为shown in the section on securing user data,然后在具有特殊权限的用户的数据库中有一个UID列表 .
所以使用这样的JSON结构:
users Power3000Uid: { ... } PufUid: { ... } admins Power3000Uid: true
安全规则如下:
{ "rules": { "users": { "$uid": { ".read": "auth.uid == $uid || root.child('admins').child(auth.uid).exists()" } } } }
在单词中 .read 规则是:"you can read this data if you're the owner of it, or if you're an admin" . 在上面的示例中,这意味着您可以阅读任何人的数据,但我只能阅读自己的数据 .
.read
根据您的确切需求,您需要在数据库中的不同位置重复admin-clause,或者(我通常做的)只在JSON树中的高级别重复一次 .
1 回答
你有没有以任何方式保护你的数据库?如果没有,我建议开始使用documentation for Firebase security rules .
我通常将我的数据库保护为shown in the section on securing user data,然后在具有特殊权限的用户的数据库中有一个UID列表 .
所以使用这样的JSON结构:
安全规则如下:
在单词中
.read
规则是:"you can read this data if you're the owner of it, or if you're an admin" . 在上面的示例中,这意味着您可以阅读任何人的数据,但我只能阅读自己的数据 .根据您的确切需求,您需要在数据库中的不同位置重复admin-clause,或者(我通常做的)只在JSON树中的高级别重复一次 .