How do I deploy Firebase Database Security rules using the command line?

后端 未结 4 552
感动是毒
感动是毒 2020-12-28 13:13

In older versions of Firebase, we could add a rules section to our firebase.json file, and upload new security rules on every deploy.

How d

相关标签:
4条回答
  • 2020-12-28 13:34

    You can use firebase deploy or firebase deploy --only database from the command line, BUT most important:

    Please note hereunder firebase.json format: The "rules" entry is under "database" entry.

    It was taken from Firebase Sample code.

    {
      "database": {
        "rules": "database-rules.json"
      },
      "hosting": {
        "public": "./",
        "ignore": [
          "firebase.json",
          "database-rules.json",
        ]
      }
    }
    
    0 讨论(0)
  • 2020-12-28 13:48

    You can use firebase deploy --only database if you only want to update database rules. It will overwrite your existing rules.

    You can check out Firebase CLI Reference for more info

    0 讨论(0)
  • 2020-12-28 13:50

    To deploy a new set of security rules, add a rules top-level key to your firebase.json.

    Example firebase.json file:

    {
      "rules": "firebase_rules.json",
      "hosting": {
        "public": "doc",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ]
      }
    }
    

    The firebase_rules.json is a JSON file that contains the security rules. Here's an example:

    {
      "rules": {
        ".read": false,
        ".write": false
      }
    }
    

    When you run firebase deploy, it will send the contents of firebase_rules.json to the server, replacing/updating any rules configurations.

    0 讨论(0)
  • 2020-12-28 13:51

    To deploy a new set of security rules with firebase cli

    firebase deploy --only firestore:rules
    
    0 讨论(0)
提交回复
热议问题