0

I am working with the expo managed workflow and I always get this Firebase error when I try to use the Firebase emulator suite. I have tried several things but i just can't connect my project(I work with an Android emulator) to the emulator suite.

This is my firebase instance;

    import firebase from "firebase/app";
    import "firebase/firestore";
    import "firebase/auth";
    
    const firebaseConfig = {
      apiKey: "",
      authDomain: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: "",
      appId: "",
      measurementId: "",
    };
    
    !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
    
    export const db = firebase.firestore();
    export const auth = firebase.auth();
    
    if (__DEV__) {
      db.settings({
        host: "localhost",
        ssl: false,
      });
      auth.useEmulator("http://localhost:9099");
    }
    
    export default firebase;

And this is the authentication part

        import { auth, db } from "./firebase";
    
    const regUsers = async (userCred) => {
      try {
        const user = await auth.createUserWithEmailAndPassword(
          userCred.email,
          userCred.password
        );
    
        if (user) {
          const currentUser = auth.currentUser.uid;
          try {
            await db.collection("users").doc(currentUser).set({
              name: userCred.name,
              email: userCred.email,
              matricNumber: userCred.matricNumber,
              dateCreated: new Date(),
            });
          } catch (error) {
            console.log(
              "Something went wrong while saving user credentials",
              error
            );
          }
          return user;
        }
      } catch (error) {
        console.log("Something went wrong while registering user", error);
      }
    };
    
    const loginUser = async (userCred) => {
      try {
        const result = await auth.signInWithEmailAndPassword(
          userCred.email,
          userCred.password
        );
        if (result) {
          const currentUser = auth.currentUser.uid;
          return currentUser;
        }
      } catch (error) {
        console.log("Something went wrong while login user", error);
      }
    };
    
    export default {
      regUsers,
      loginUser,
    };

Anytime I try to login or register a user I get that error. Please does anyone know what else I can try. The error only comes up when I try to connect to the emulator, and internet connection is horrible where I am. I additionally noticed this warning in my firestore debug-log. "io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead INFO: Detected non-HTTP/2 connection.

Tomiwa
  • 11
  • 5
  • I found a [related case](https://stackoverflow.com/questions/40052162/firebase-authentication-firebasenetworkexception-a-network-error-such-as-timeo) that maybe is useful, there is some possible causes to the error you are getting. – Vicky Jun 14 '21 at 15:45
  • I had already tried the things they suggested on that page. Can a managed expo project actually work with the emulator suite? – Tomiwa Jun 16 '21 at 08:56
  • You may find the info in this issue useful: https://github.com/firebase/firebase-tools/issues/3258 – Javier A Jun 28 '21 at 15:03
  • And this one: https://stackoverflow.com/questions/62097398/firebase-firestore-works-with-real-database-but-not-emulator – Javier A Jun 28 '21 at 15:23

1 Answers1

1

Apparently, when you're working with an emulator, you should replace localhost with 10.0.2.2:8080 and it should work just fine.

Tomiwa
  • 11
  • 5