2

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,
})
Will
  • 67
  • 1
  • 8
  • I think you're going to have to provide more debugging information than "it is unable to access it". – Doug Stevenson Dec 30 '20 at 20:09
  • is there a way to edit these firestore host and ssl settings for realtime database? I have firestore working with expo but not realtime database – peter Aug 25 '21 at 01:06

2 Answers2

3

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.

Will
  • 67
  • 1
  • 8
  • Do you know what to do for realtime database? I got firestore working but my realtime database does not connect :/ – peter Aug 25 '21 at 01:23
2

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

Dharman
  • 30,962
  • 25
  • 85
  • 135