android - 在Firebase-Realtime Database上使用什么规则让用户注册和登录?

标签 android json firebase firebase-realtime-database

为了让 Android 用户通过我的应用程序注册和登录,我设置了 .read.writetrue。我的问题是任何人都可以访问用户 JSON 文件,因为它是公共(public)。如何仅通过应用程序和 Firebase 控制台限制对数据库的访问?以下是规则:

{
    "rules": {
        ".read": true,
        ".write": true
    }
}

最佳答案

使用以下规则:

{
  "rules": {
      ".read": "auth != null",
      ".write": "auth != null"
  }
}

您将仅向经过身份验证的用户授予readwrite 访问权限。有关详细信息,请参阅有关 Firebase security rules 的官方文档.

根据您的评论,您应该验证执行操作的用户是否实际上是经过身份验证的用户。因此,例如,假设您只希望经过身份验证的用户能够访问他们的帐户,则需要以下规则:

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

关于android - 在Firebase-Realtime Database上使用什么规则让用户注册和登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54114203/

相关文章:

python - 为什么 'pip install json'显示版本错误

java - 你应该在 addOnCompleteListener 里面写什么?

android - 在 Android 的后台线程上初始化 Firebase 是否安全?需要注意什么?

android - 如何在 Firebase 项目中启用 Google Analytics

android ant build 在 ant release 命令上失败

java - org.apache.struts2.json.JSONException : org. hibernate.LazyInitializationException:未能延迟初始化集合

ios - 检索给定特定字段的 Firebase 数据

android - DDMS 不显示我的日志

android - 在 Android 上使用 H2 数据库和 OrmLite 的速度问题

java - 如何从 "assets"目录读取文本文件作为字符串?