Firebase - 如何为超级用户授予读写权限

时间:2016-06-27 09:47:28

标签: android firebase firebase-realtime-database firebase-authentication firebase-security

如何向firebase实时数据库中的某个用户授予超级用户读取其他用户数据,例如(这仅适用于经过身份验证的用户,不允许其他人读取或写入)

{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid",
      }
    }
  }
}

1 个答案:

答案 0 :(得分:2)

这有效:

{
  "rules": {
    "users": {
      ".read": "'SUPER_USERS_ID_HERE' === auth.uid",
      ".write": "'SUPER_USERS_ID_HERE' === auth.uid",
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

您可以从Firebase控制台的Auth部分获取超级用户的UID。例如:

".write": "'0d52a06d-3e0b-4106-b7aa-924866fb2bff' === auth.uid"

注意UID周围的撇号。