【问题标题】:I don't understand what's wrong with my rules我不明白我的规则有什么问题
【发布时间】:2020-02-13 16:49:54
【问题描述】:

我已经在 RealtimeDatabase 中设置了我的规则,这样只有创建内容的人才能阅读或更新它,但不幸的是,这些规则不能这样工作。

我还尝试了其他各种安全性较低的规则,因此问题不在于我的应用程序。

这些是我的规则,不允许我读取自己的数据。

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

我的应用中的代码。

路径:用户/uid/信息 值:imageUrl

fun getFireBaseValue(Path: String, Value: String): String {
        FirebaseDatabase.getInstance().getReference(Path).child(Value)
            .addValueEventListener(object : ValueEventListener {
                override fun onDataChange(p0: DataSnapshot) {
                    val fetchedValue = p0.value.toString()
                }

                override fun onCancelled(p0: DatabaseError) {
                }
            })
    }

我期待一个我之前写的 URL。但是我得到一个错误:“DatabaseError: Permission denied”。 据我了解规则,我应该被允许读取我自己的数据。

【问题讨论】:

  • 请编辑问题以显示无法按您期望的方式工作的代码。请详细解释该代码中使用的任何变量的内容。
  • 好了,希望现在能明白了。

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


【解决方案1】:

如果您的代码示例中的 Path 变量是 user/uid/info,则规则不允许访问该位置。这些规则只允许每个用户访问posts/uid。规则中的路径需要与代码中的路径匹配才能允许访问。

【讨论】:

    猜你喜欢
    • 2021-04-26
    • 2022-08-08
    • 1970-01-01
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    相关资源
    最近更新 更多