在规则上增加Firebase时间戳日期

时间:2020-01-17 01:58:11

标签: firebase flutter google-cloud-firestore firebase-security

您好,实际上有没有从该规则增加时间戳的方法?我正在使用Cloud Firestore

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    // This rule allows anyone on the internet to view, edit, and delete
    // all data in your Firestore database. It is useful for getting
    // started, but it is configured to expire after 30 days because it
    // leaves your app open to attackers. At that time, all client
    // requests to your Firestore database will be denied.
    //
    // Make sure to write security rules for your app before that time, or else
    // your app will lose access to your Firestore database
    match /{document=**} {
      allow read, write: if request.time < timestamp.date(2020, 1, 16);
    }
  }
}

它说到2020年1月16日,如果小于该值,它将允许从我的数据库读取和写入数据。但是它已经于1月17日在菲律宾这里举行。

我尝试将timestamp.date从2020, 1, 16更改为2020, 3, 15,但我的Flutter应用仍未从数据库读取任何内容。

我期望的是在增加时间戳记日期之后,它将允许我的应用程序从数据库读取直到给定时间。现在,即使我增加它,该应用程序也不会从数据库中读取任何内容

这是我的代码:

  @override
  Widget build(BuildContext context) {

    width = MediaQuery.of(context).size.width;

    return SafeArea(
        child: Scaffold(
          backgroundColor: Color(0xFF0d192a),
        appBar: CustomAppBar(height: 90),
        drawer: DrawerNiVlad(),
        body: ListView(
          children: <Widget>[


          ArlTitleText('EXPLORE V!'),
          sb5,
          HeaderCarousel(),
          sb30,


          ArlTitleText('DISCOUNT SECTION'),
          sb5,
          // DiscountWidget(),
          sb30,

          ArlTitleText('DUMMY SECTION'),
          ArlBodyText('Lorem ipsum yes yes show boom tarat tarat yea boy Lorem ipsum yes yes show boom tarat tarat yea boy Lorem ipsum yes yes show boom tarat tarat yea boy'),
          sb30,

        ],
        ),
      ),
    );
  }

这些部分的内容:折扣和虚拟部分来自数据库,因为它在我的vscode中显示此错误,所以不会出现:

enter image description here

和来自Firebase的电子邮件中说:

You chose to start developing in Test Mode, which leaves your Cloud Firestore database completely open to the Internet. Because your app is vulnerable to attackers, your Firestore security rules were configured to stop allowing requests after the first 30 days.
In 0 day(s), all client requests to your Firestore database will be denied. Before that time, please write strong security rules that allow your app to function while appropriately protecting your data. Analysis is run daily; if you've modified your rules in the last 24 hours those changes may not be accounted for.

1 个答案:

答案 0 :(得分:0)

您需要设置身份验证才能解决此问题。如果您仍然想要基于时间戳的访问,则仍然需要使用身份验证。我建议通读此 guide 以了解有关警告的更多详细信息。

相关问题