Reputation: 529
I'm creating an authentication workflow for my android app. I'm allowing users to sign in with username/password and various OAuth providers. I'm validating emails and password so that, I know the information I'm passing to Firebase is valid. I'm using com.google.firebase:firebase-auth:9.6.1
When I execute the following code, I get a callback that says the operation not successful with an error.
mFirebaseAuth.signInWithEmailAndPassword(username,password).addOnCompleteListener(this);
Callback function or completion listener tells me
com.google.firebase.FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host) has occurred.
The username I'm passing doesn't exist yet. So, I would assume to see some kind of error stating the user doesn't exist. Am I passing something incorrectly or am I assuming incorrectly? I can also see that in the Firebase documentation, the iOS library has a various error codes common to all API methods section where as the Android section doesn't show this. One of these exceptions is FIRAuthErrorCodeUserNotFound
. So, does that functionality even exists in the Android library?
Upvotes: 34
Views: 60784
Reputation: 4048
Another possible reason might be, that the clients that are getting this error are sending request from China, because all URLs such as *.google.com and *.googleapis.com are blocked in China.
Apparently Firebase has a China service at https://firebase.google.cn, but I didn't have chance to check it out yet. You can also read more on this in this Stackoverflow post: https://stackoverflow.com/a/42620514/1372783
Upvotes: 0
Reputation: 19
I have faced this problem after searching a lot i got the solution, In my case it was happening due to the restriction of background data.
If you turn off background data of Google Service Framework. Check & turn on it. It worked for me.
Upvotes: 0
Reputation: 5992
It could be a million things my advice based on my experience is check the firebase logs and work the problem from there.
In my case I was hitting the endpoint successfully but it was generating a catch error because of an invalid variable rowsCompany on the res.json({...response...} )
Upvotes: 0
Reputation: 189
I have also got the same error and there are sometimes very small things which we forget Like -> Turn On Internet as
com.google.firebase.FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host) has occurred
This is FirebaseNetwordException there might be case when Host is not Reachabe like mentioned above so check you connectivity
aslo check weather you have provided Internet Permissions in Manifest or not.
hope it will solve your problem
Upvotes: 0
Reputation: 2189
Upvotes: 6
Reputation: 6462
If you are using Genymotion, it could be that you did not activate Open Gapps (in the top right corner)
Upvotes: 0
Reputation: 121
I had a similar problem accessing firebase. In my case, the problem was that I was doing this on a real device via the debugger. Once I ran the code "normally" the error vanished. So, it might be helpful to check whether the debugger is getting in the way.
Upvotes: 0
Reputation: 25525
Can also happen if your authDomain
is set improperly in your firebase keys for web projects.
Upvotes: 0
Reputation: 10232
changing from <form></form>
to <div></div>
solved this problem:
"A network error (such as timeout, interrupted connection or unreachable host) has occurred in a form element in the HTML. Small bug."
Upvotes: 25
Reputation: 1327
In your AndroidManifest.xml add, it works for me
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Upvotes: 3
Reputation: 1521
In my case the issue is due to mismatch versions of dependencies, then I have changed dependencies like below
implementation 'com.google.firebase:firebase-auth:+'
implementation 'com.google.firebase:firebase-core:+'
implementation 'com.google.android.gms:play-services-auth:+'
implementation 'com.firebaseui:firebase-ui-auth:+'
then its started working perfectly.
Upvotes: 0
Reputation: 11
I resolve the problem fixing the date of my cell phone were one year late, when I fixed the date, everything worked well again and the error disappear, I hopping this help you
Upvotes: 1
Reputation: 2606
If you do this check in form onSumbit handler, you need to preventDefault before sending a request.
This is a snippet (React) that works:
class LoginComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
};
this.login = this.login.bind(this);
this.handleLoginChange = this.handleLoginChange.bind(this);
this.handlePasswordChange = this.handlePasswordChange.bind(this);
}
handleLoginChange(event) {
this.setState({
email: event.target.value,
password: this.state.password,
});
}
handlePasswordChange(event) {
this.setState({
email: this.state.email,
password: event.target.value,
});
}
login(event) {
event.preventDefault();
firebase.auth()
.signInWithEmailAndPassword(this.state.email, this.state.password)
.then(function(user) {
window.alert('OK' + user);
},
function(error) {
window.alert('ERR' + error);
});
}
render() {
return (
<form onSubmit={this.login}>
<TextField hintText="login" value={this.state.email} onChange={this.handleLoginChange} /><br/>
<TextField hintText="password" type="password" value={this.state.password} onChange={this.handlePasswordChange} /><br/>
<RaisedButton type="submit" label="Login" primary={true} />
</form>
)
}
}
Upvotes: 3
Reputation: 13645
Check your rewrites in firebase.json
, make sure you don't rewrite auth provider url /__/
{
"database": {
"rules": "database.rules.json"
},
"storage": {
"rules": "storage.rules"
},
"hosting": {
"public": "public",
"rewrites": [
{
"source": "!/__/**",
"destination": "/index.html"
},
{
"source": "**/!(*.js|*.html|*.css|*.json|*.svg|*.png|*.jpg|*.jpeg)",
"destination": "/index.html"
}
]
}
}
Also it could be service worker problem. See https://github.com/Polymer/polymer-cli/issues/290
Upvotes: 0
Reputation: 686
<a (click)="login()" class="nav-link">Login</a>
Do not put href
attribute into tag a
. It is help to solved my case
Upvotes: 3
Reputation: 604
It can also happen when google play services are not running. Try to launch play store and check if it is working. If not reboot of device issue.And also compare the google play services using in the project and google play services in the device are same if not update google play services.
This is just a minor but possible case where it gives the exception.
Upvotes: 23
Reputation: 908
I was facing the same issue. what solved my problem by clear extra space in API_KEY, so my suggestion is to check your GoogleService-Info.plist for
I think this might help you
Upvotes: 2