New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database.rules.json
is not applied to the default RTDB instance in the emulator.
#3124
Comments
This has been driving me crazy. Do you know of a workaround @aameen951? I tried using the instance flag on the CLI, and also setting a target in firebase.json, but to no avail. I'm not sure I'm setting it right as the docs aren't that explicit. |
Thanks @StevenHallLtd and @aameen951 for reporting, let me take a look at this. |
@StevenHallLtd At first, I didn't know it was happening. But when I start to use queries with filters it became an annoying problem. import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { promises as fs } from 'fs';
import * as path from 'path';
// This is the database instance
const db = admin.database();
// check if the firebase function is running inside the emulator.
const IS_INSIDE_EMULATOR = process.env.FUNCTIONS_EMULATOR === 'true';
if(IS_INSIDE_EMULATOR)
{
// read the rules file.
fs.readFile(path.join(__dirname, "../../../database.rules.json"), 'utf8').then((source) => {
// manually set the rules on the database.
db.setRules(source);
});
} The one downside to this workaround so far is that if you change the rules file it won't update automatically, you have to go to any file that belongs to functions and save it to make functions reload and cause the above code to run again. |
Fixed in #3146 and will be included in the next release. |
Hi there,
This #2979 pull request fixed one part of the problem mentioned in #2965 where the default instance in hosting is different from the default instance in firebase-admin and both of them now reference the same instance which is
project-id-default-rtdb
.However, the rules in
database.rule.json
are still being applied toproject-id
instead ofproject-id-default-rtdb
, and I don't know how to change that manually.[REQUIRED] Environment info
firebase-tools: 9.3.0
Platform: Windows
[REQUIRED] Test case
functions/index.js
database.rules.json
[REQUIRED] Steps to reproduce
curl localhost:9000/.settings/rules.json?ns=project-id-default-rtdb -H "Authorization: Bearer owner"
curl localhost:9000/.settings/rules.json?ns=project-id -H "Authorization: Bearer owner"
[REQUIRED] Expected behavior
Since
project-id-default-rtdb
is now the default instance, thedatabase.rules.json
should also be applied toproject-id-default-rtdb
instance instead ofproject-id
instance.[REQUIRED] Actual behavior
Now,
database.rules.json
is applied toproject-id
.The text was updated successfully, but these errors were encountered: