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

家住魔仙堡 提交于 2019-11-30 02:48:42

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

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",
    ]
  }
}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!