首页 > 解决方案 > Firebase 规则:无法始终如一地工作

问题描述

我正在使用一种结构来将用户朋友保存在实时数据库中,如下所示:

friends
    $user_id:
        -$friend_id1
            -name: ""
            -id: ""
        -$friend_id2
(...)

我的规则如下所示:

"friends":{
     "$id": {
        ".read": "auth != null && $id === auth.uid",
        ".write": false,
      },
  },

在我的 iOS 应用程序中,我可以访问其他人的朋友,尽管我不应该这样做。此外,这似乎主要是一个单一视图中的问题,因为当我更改

"read": false

我仍然可以在该特定视图中读取此数据。然而,在所有其他视图中,我不能这样做,尽管代码几乎相同(除了观察 ( .childAdded) 而不是 ( .value)。

我在打电话

let friends_ref = Database.database().reference().child("friends").child(self.friend_id)
    friends_ref.observeSingleEvent(of: .value, with: { (snapshot) in

    //CODE

})

此外,加载好友所需的时间,因此获得回调,甚至需要 >5 秒才能获得 5 个好友。

这怎么可能发生?

此致

标签: iosswiftfirebasefirebase-realtime-databasefirebase-security

解决方案


推荐阅读