Reputation: 232
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?
Upvotes: 8
Views: 11789
Reputation: 754
In my case it worked when I changed
auth.useEmulator('http://localhost:9099')
to
auth.useEmulator('http://127.0.0.1:9099')
in my jest tests.
Upvotes: 1
Reputation: 1649
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)
Upvotes: 1
Reputation: 535
I had also the same problem, Just restart your IDE and emulator and make sure that have connected wifi. Then open again and run your app.
Upvotes: 0
Reputation: 101
In my case It happened using the Android Emulator. Closing and restarting the Emulator solved the problem
Upvotes: 0
Reputation: 2189
1- Reason is Simple ! Check if Device has internet connection. 2- if you have google services enabled
Upvotes: 0
Reputation: 8760
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.
Upvotes: 2