Open mdo5004 opened 3 years ago
@mdo5004 what's happening here is that you're sending an Auth emulator token to the production Realtime Database server, which is causing an error (as it should).
Can you show some of your code where you call initializeApp
and useEmulator
?
Thanks for your reply @samtstern! Here is my init code:
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';
const firebaseConfig = {
...
};
const fire = !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
export default fire;
firebase.database().useEmulator('localhost', 9000);
firebase.database.enableLogging(true);
console.log('using database emulator on port 9000');
firebase.auth().useEmulator('http://localhost:9099');
console.log('using auth emulator on port 9099');
Hmmm nothing looks obviously wrong, but can you try changing your firebase.database()
and firebase.auth()
calls to fire.database()
and fire.auth()
? Also I assume elsewhere in your app when you access the database you're using fire.database()
.
Can confirm this is happening to me as well. Using firebase@8.4.2
.
Changing my code to this does not fix the issue, unfortunately.
fire.database().useEmulator('localhost', 9000);
firebase.database.enableLogging(true);
console.log('using database emulator on port 9000');
fire.auth().useEmulator('http://localhost:9099');
console.log('using auth emulator on port 9099');
This sounds like it may be related to https://github.com/firebase/firebase-js-sdk/issues/4110
Try putting your auth emulator line first, before the other emulators.
Thanks for your reply, but that did not work :-/
The issue seems to be isolated to the client-to-rtdb connection. Starting the functions emulator and adding a functions.auth.user().onCreate
trigger successfully writes to the emulated rtdb.
Managed to get it working by overriding the config:
const config = {
// your config
};
if (location.hostname === 'localhost') {
config.databaseURL = 'http://127.0.0.1:9000/?ns=firebase-project-id';
}
For some reason, database().useEmulator
doesn't seem to work as expected. Unsure if it's an edge case related to the following line or something else:
const fire = !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
This has kept me from using the database emulator for a while, @sincraianul fix fixes it for me too.
[REQUIRED] Environment info macOS 11.2.3 node 12.20.1 firebase-tools 9.10.0 firebase JS SDK 8.4.2
[REQUEST] Test case Not receiving data from database emulator when used with Auth emulator.
Database emulator logs:
[REQUIRED] Steps to reproduce
[REQUIRED] Expected behavior
Data should be received by web app
[REQUIRED] Actual behavior
Web app does not receive data from database
Originally posted by @mdo5004 in https://github.com/firebase/firebase-tools/issues/2758#issuecomment-825871943
Edit: dependencies