javascriptreact-nativefirebase-authenticationreact-native-firebasefirebase-tools

How to use react-native-firebase auth emulation?


im using react-native-firebase v21.6.1 and im trying to start the auth service emulation. Ive gotten the firestore and functions emulation working.

firebase.json

"emulators": {
  "functions": {
    "port": 5001
  },
  "firestore": {
    "port": 8080
  },
  "auth": {
    "port": 9099
  },
  "ui": {
    "enabled": true
  },
  "singleProjectMode": true
}

app.js:

import functions from '@react-native-firebase/functions';
import firestore from '@react-native-firebase/firestore';
import auth from '@react-native-firebase/auth';

...
if (__DEV__) {
  firestore().useEmulator('localhost', 8080);
  functions().useEmulator('localhost', 5001);
  auth().useEmulator('http://localhost:9099');
}

It seems to have connected successfully:

enter image description here

Using auth().createUserWithEmailAndPassword would throw this error:

Error: [auth/network-request-failed] A network error has occurred, please try again.]

I execute npx expo run:ios to start a development build on the ios simulator.


Solution

  • Marco's answer is right,

    I was facing the same issue as you and if you change

    if (__DEV__) {
        firestore().useEmulator('localhost', 8080);
        storage().useEmulator('localhost', 9199);
    -   auth().useEmulator("http://localhost:9099"); // from this
    +   auth().useEmulator("http://127.0.0.1:9099"); // to this
    }
    

    Then i suggest to rebuild the app and log out of your app.

    You will be able to see something like this in the console

    screenshot of expected result