【问题标题】:Firebase Realtime database security rules for query用于查询的 Firebase 实时数据库安全规则
【发布时间】:2020-12-03 22:06:24
【问题描述】:

在我的应用程序和客户端我运行一个查询:

      .database()
      .ref()
      .child(`Posts`)
      .orderByChild('userID_DatePosted')
      .equalTo(userID + '_' + myDate)
      .once('value')

myDate 是一个变量,我在之前的交互中将它存储在客户端。 我在 Firebase 中的安全规则应如下所示:

            ".read": 
              query.orderByChild == 'userID_DatePosted' &&
              query.equalTo == auth.uid + '_' + ANYDATE,

我需要输入什么而不是 ANYDATE 以便任何包含 auth.uid 且在“_”之后的任何查询都返回 true?

【问题讨论】:

    标签: javascript firebase firebase-realtime-database firebase-security


    【解决方案1】:

    由于query.equalTo 是一个字符串值,您可以在安全规则中使用任何operations that work on a string

    例如:

    query.equalTo.startsWith(auth.uid+'_')
    

    我不完全确定 ANYDATE 是什么,但您也许可以使用正则表达式捕获:

    query.equalTo.matches(/_[0-9]+/)
    

    如果需要,您可以将这两个条件与&& 结合起来。

    【讨论】:

    • 感谢您的回答。这就是我一直在寻找的
    猜你喜欢
    • 2020-08-08
    • 2022-01-18
    • 2020-12-28
    • 2021-10-26
    • 2021-12-05
    • 2021-06-20
    • 2021-02-13
    • 2018-08-27
    相关资源
    最近更新 更多