Search code examples
firebasetestinggoogle-cloud-firestorefirebase-cli

Can i access the firebase realtime database security rules via REST?


I'm looking to set up emulated testing of my security rules, and currently the docs recommend loading your rules into a file and then reading that file into the emulator.

const rules = fs.readFileSync("database.rules.json", "utf8");

What I'd rather do is load in the latest security rules from my project, so that I know that any changes I make to it can be tested instantly and are working properly.

Is it possible to access the security rules via REST?


Solution

  • According to the reference documentation you can retrieve security rules via a REST GET call. From there:

    curl 'https://[PROJECT_ID].firebaseio/.settings/rules.json?auth=FIREBASE_SECRET'
    curl -X PUT -d '{ "rules": { ".read": true } }' 'https://[PROJECT_ID].firebaseio/.settings/rules.json?auth=FIREBASE_SECRET'