【问题标题】:How do I make a rule in firebase realtime database security rule so that only those users can write the data if they are in certain time slot?如何在firebase实时数据库安全规则中制定规则,以便只有那些用户在特定时间段内才能写入数据?
【发布时间】:2021-07-01 23:32:54
【问题描述】:

基本上,如果我在集合中有一个具有特定字段的文档,比如说开始时间和结束时间。现在我希望用户传入的写入请求仅在该用户的时间低于该开始时间和结束时间时通过。另外让我们假设用户的 uid 也不为 null(这意味着用户已通过身份验证)。

【问题讨论】:

    标签: firebase firebase-realtime-database google-cloud-firestore firebase-authentication firebase-security


    【解决方案1】:

    为了只允许经过身份验证的用户写入,您可以使用Firebase authentication。例如:

    {
      "rules": {
        "some_path/$sub_path": 
          ".write": "auth.uid != null
          }
        }
      }
    

    不幸的是,无法在满足特定时间段时验证写入,但是,您可能需要考虑使用 predefined variables 之一的函数,例如 now。 您也可以提交feature request 来添加此功能。

    【讨论】:

    • 谢谢...这很有帮助
    • 很抱歉,我无法为您的答案投票……因为我的声誉太低了。
    猜你喜欢
    • 1970-01-01
    • 2022-11-11
    • 2020-07-11
    • 2020-08-08
    • 2016-03-21
    • 2019-10-11
    • 2020-01-15
    • 2019-01-07
    相关资源
    最近更新 更多