firebase-tools: Real time database fails when using Auth emulator
[REQUIRED] Environment info
firebase-tools: 8.14.1
Platform: macOS
[REQUIRED] Test case
In a web app:
firebase.initializeApp({
apiKey: "redacted",
authDomain: "redacted",
databaseURL: "redacted",
projectId: "redacted",
storageBucket: "redacted",
messagingSenderId: "redacted",
appId: "redacted",
measurementId: "redacted",
})
authInstance = firebase.auth()
firestoreInstance = firebase.firestore()
rtbdInstance = firebase.database()
authInstance.useEmulator("http://localhost:9099/")
rtbdInstance.useEmulator("localhost", 9000)
firestoreInstance.useEmulator("localhost", 8080)
rtbdInstance.ref().once("value", r => console.log(r.val())) // fails and logs a warning
[REQUIRED] Steps to reproduce
rtbdInstance.ref().once("value", r => console.log(r.val())) // fails and logs a warning
If I don’t use the auth emulator it works fine, fetching my local database
[REQUIRED] Expected behavior
I should get data
[REQUIRED] Actual behavior
No data is returned, and a warning is logged into the dev tools console:
@firebase/database: FIREBASE WARNING: Provided authentication credentials for the app named "[DEFAULT]" are invalid. This usually indicates your app was not initialized correctly. Make sure the "apiKey" and "databaseURL" properties provided to initializeApp() match the values provided for your app at https://console.firebase.google.com/.
My hunch is that the problem could be:
- the database emulator doesn’t know that auth is being emulated and verifies the token against prod
- I’ve got an out of date database emulator? I have
i database: downloading firebase-database-emulator-v4.6.0.jar
- there is some specific order the various
useEmulator
calls have to be made in.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (9 by maintainers)
@tomhicks thanks for reporting! On the surface it looks like you’re doing everything correctly so one of us will have to try and reproduce this and dig in.