-
Notifications
You must be signed in to change notification settings - Fork 409
Description
Describe your environment
- Operating System version: Windows 10 Pro 20H2
- Firebase SDK version: 9.4.2
- Firebase Product: database
- Node.js version: 12.15.0
- NPM version: 6.13.4
Describe the problem
When using the rules APIs of the database (setRules or getRules) against the emulator, the DatabaseRulesClient does not automatically change the URL to FIREBASE_DATABASE_EMULATOR_HOST, while the other APIs do. Moreover, it does not use the EmulatorAdminTokenProvider. Instead, it tries to get a real token.
Steps to reproduce:
- setup env variables for FIREBASE_DATABASE_EMULATOR_HOST and GCLOUD_PROJECT
- run a production-ready code that should utilize the emulator when env variables are set
Relevant Code:
const admin = require('firebase-admin');
const rules = require('./database.rules.json');
const app = admin.initializeApp();
app.database('https://database-instance.firebasedatabase.app').setRules(rules)
.then(res=>console.log('Rules set successfully'))
.catch(err=>console.error(err));
Analysis
The initStandalone method from @firebase/database is aware of FIREBASE_DATABASE_EMULATOR_HOST and switches to emulator URLs and EmulatorAdminTokenProvider. However, the DatabaseRulesClient does not use getToken nor the URL from the RTDB instance initialized by initStandalone.
I'm not too familiar with the repo, but I see that the URL and the authProvider are deep inside private fields of the RTDB instance and Repo classes. I would be happy to help to create a PR if anyone can provide me with a nice way to get the actual URL and provider from the RTDB instance.