Firebase Authentication FirebaseNetworkException: A network error occurred (for example, a timeout, a disconnected connection, or an unavailable host)

I am creating an authentication workflow for my Android application. I allow users to login with username / password and various OAuth providers. I check emails and password, so I know that the information that I transmit to Firebase is valid. I am using com.google.firebase:firebase-auth:9.6.1

When I execute the following code, I get a callback that says the operation failed with an error.

 mFirebaseAuth.signInWithEmailAndPassword(username,password).addOnCompleteListener(this); 

Callback function or completion listener inform me

 com.google.firebase.FirebaseNetworkException: A network error (such as timeout, interrupted connection or unreachable host) has occurred. 

The username I pass in does not exist yet. So, I would suggest some kind of error indicating that the user does not exist . Am I transferring something incorrectly or mistakenly accepting it? I also see that in the Firebase documentation, the iOS library contains various error codes common to all API sections, where this is not displayed in the Android section. One of these exceptions is FIRAuthErrorCodeUserNotFound . So, does this functionality even exist in the Android library?

+14
java android firebase firebase-authentication
source share
13 answers

This can also happen if Google Play services are not running. Try to launch the game store and see if it works. If you do not restart the device, and also compare the Google Play services that are used in the project, and the Google Play services on the device will be the same if the google play services are not updated.

This is just a minor but possible case where it gives an exception.

+11
source share

switching from <form></form> to <div></div> solved this problem:

"A network error occurred in the form element in the HTML file (for example, a timeout, a disconnected connection, or an unavailable host). A small error."

+15
source share
 <a (click)="login()" class="nav-link">Login</a> 

Do not put the href attribute in the a tag. It helps solve my case.

+3
source share

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"/> 
+2
source share

I ran into the same problem. which solved my problem by clearing the extra space in API_KEY, so my suggestion is to check your GoogleService-Info.plist for

  • API_KEY is correct (no extra spaces)
  • GOOGLE_APP_ID
  • CLIENT_ID

I think it can help you.

+1
source share

If you perform this check in the form of an onSumbit handler, you need to prevent Default before sending the request.

This is the fragment (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> ) } } 
+1
source share

I solve the problem fixing the date of my cell phone, was one year late, when I set the date, everything worked fine again, and the error went away, I jump, it will help you

+1
source share

Check your rewrites in firebase.json , make sure you are not rewriting the URL of the authorization provider /__/

 { "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" } ] } } 

It can also be a worker problem. See https://github.com/Polymer/polymer-cli/issues/290

0
source share

In my case, the problem is related to the mismatch of dependency versions, so I changed the dependencies as shown 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 it started to work perfectly.

0
source share

This is actually a resolution problem. Add these lines to your file "platform / android / AndroidManifest.xml":

 <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"/> 

and

install cordova-plugin-whitelist

and allow navigation for everyone in config.xml

 <allow-navigation href="*" /> 
0
source share

This can also happen if your authDomain not configured correctly in Firebase keys for web projects.

0
source share

I had a similar problem with accessing the database. In my case, the problem was that I was doing this on a real device through a debugger. As soon as I ran the code "normal", the error disappeared. Thus, it can be useful to check if the debugger is interfering.

0
source share

I ran into this problem after a lot of searching, I got a solution, in my case it happened due to background data limitation

-one
source share

All Articles