【问题标题】:Firebase security rules for .indexOn : unique uid in iOS/Swift.indexOn 的 Firebase 安全规则:iOS/Swift 中的唯一 uid
【发布时间】:2016-06-17 17:29:14
【问题描述】:

我看到了几个关于在 Firebase 中放置特定安全规则的问题。我已经想出了在这些情况下如何做到这一点。现在我正在通过 authData.uid 保存信息并获取此信息....

[Firebase] Using an unspecified index. Consider adding ".indexOn": "4eb8920a-e407-4488-bce4-c6f64f7b0891" at /UserVideo to your security rules for better performance

如何为唯一密钥添加此类安全规则以及如何添加?这是我的查询...

let videoRef = self.ref.childByAppendingPath("UserVideo")
        videoRef.queryOrderedByChild("\(currentUser)").queryLimitedToFirst(1)
            .observeEventType(.ChildAdded, withBlock: { snapshot in
                if snapshot != nil

欢迎任何见解!

* 更新 *

是的。我忘了添加 currentUser 是...

let currentUser = ref.authData.uid

查询实际上会返回相关信息。它还包括指定的警告。将尝试第二个答案几次,如果可行,请更新此帖子。如果其他人有任何想法,请发表。

【问题讨论】:

  • 这听起来像是一个将逐渐开始使用更多时间的查询。 videoRef.queryOrderedByChild("\(currentUser)").queryLimitedToFirst(1)。如果您想存储每个用户的视频,请将它们存储为/UserVideo/$uid/$videoid。然后,您的查询将变为直接访问 videoRef.childByAppendingPath("\(currentUser)"),并且性能将不取决于用户数量。
  • 除了上面的建议之外,如果没有看到相关 JSON 的 sn-p 就很难给出答案(请作为文本,没有截图)。

标签: swift firebase firebase-security


【解决方案1】:

看到这个:Security & Rules Quickstart

安全和 Firebase 规则用于确定谁对您的数据库具有读写权限,并确保该数据的结构。它们位于应用程序仪表板的安全选项卡中。它们有三种口味:.write.read.validate

在回答您的问题时,通过同时使用 validatewrite 添加唯一密钥的安全规则。

一个例子是:

{
"rules": {
"foo": {
  // /foo is readable by the world
  ".read": true,
  // /foo is writable by the world
  ".write": true,
  // data written to /foo must be a string less than 100 characters
  ".validate": "newData.isString() && newData.val().length < 100"
}
    }
       }

这有帮助吗?

【讨论】:

    猜你喜欢
    • 2016-09-29
    • 2017-07-11
    • 2016-06-03
    • 2021-04-09
    • 2018-01-12
    • 2014-11-24
    • 2017-01-02
    • 1970-01-01
    相关资源
    最近更新 更多