Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase 'A network error (such as timeout, interrupted connection or unreachable host) has occurred.'

I'm trying to write some tests for my database client which requires me to first authenticate into Firebase.

I'm using Jest as my test runner.

My test looks like:

it ('should sign in ', async (done) => {
  try {
    await auth.signInWithEmailAndPassword('[email protected]', 'testuser');
  } catch (e) {
    console.log(e);
  }
  done();
});

My firebase app has been initialized and I have validated that the API key is correct.

A couple of interesting notes are that even though I get:

'A network error (such as timeout, interrupted connection or unreachable host) has occurred.' 

On the firebase console, I see that my test user has signed in. Mirroring: Firebase throws “auth/network-request-failed” on signInAnonymously() while running jest tests

It doesn't seem like an authentication issue (wrong password/wrong email) as I get the same error for attempting to login as a user that does not exist.

Sign in via launching my app through the browser and inputting credentials into input fields works with no issues.

Any ideas?

like image 865
Evan Avatar asked Mar 13 '18 20:03

Evan


2 Answers

I've had similar results when there was Proxy and/or certificate issues blocking things.

What I would do is first enable logging: firebase.database.enableLogging(true);

Then take a look at what it says. If you can't see what is blocking I'd then run Wireshark, we were able to see what was happening then.

like image 101
Dennis Smolek Avatar answered Oct 20 '22 12:10

Dennis Smolek


This problem occurs when there is no active internet connection in your mobile. I received the same error because I forgot to enable my network connection in my device. First check your Android manifest file to make sure you have granted network permissions. In my case it was done. So I used my emulator then it started working fine. (For more thorough diagnasis you can use if clause to check whether internet connection is active or not)

like image 22
Neyomal Avatar answered Oct 20 '22 13:10

Neyomal