Reputation: 87
I'm trying to access the firestore emulator (hosted locally) through my Expo app on both physical and emulated devices, which both don't work. When I make a call to the emulated firestore database, such as setting a document, it doesn't show up on the UI. However, if I run the exact same code for the real firestore it works normally.
My firebase.json config is:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"emulators": {
"firestore": {
"port": 8080
},
}
}
For the Expo app on the android emulator I set up my config as:
firebase.firestore().settings({
host: "10.0.2.2:8080",
ssl: false,
})
And for the Expo app on my physical android device:
firebase.firestore().settings({
host: "localhost:8080",
//I've also tried "192.168.68.109:8080" my computer's IP
ssl: false,
})
Upvotes: 2
Views: 1046
Reputation: 51
If you're testing on a physical device, you'll have a better time connecting using your computer's IP address. Rather than hardcoding it, you can use a built-in variable: Constants.manifest.debuggerHost?.split(":").shift()
.
Wrote up a short explanation on that here:
https://dev.to/haydenbleasel/using-the-firebase-local-emulator-with-expo-s-managed-workflow-5g5k
Upvotes: 2
Reputation: 87
It turns out you need to specify the host on your firebase.json as
"emulators": {
"firestore": {
"port": 8080
"host": "0.0.0.0"
},
As for the config for the Expo app on the physical device, instead of "localhost:8080" put your computer's (or whatever your hosting on in your network) IP address followed by ":8080".
If all this still doesn't work try the command "firebase use <YOUR_PROJECT_ID>" in your project directory and it should work.
Upvotes: 4