auth/network-request-failed firebase react JS

7,867 views
Skip to first unread message

lrenc...@uc.cl

unread,
Sep 22, 2016, 4:48:56 PM9/22/16
to Firebase Google Group
firebase:3.3.0
React JS

I'm trying to connect to firebase auth, but I get rejected. Something is blocking my connection, I don't know if it's in the client side. It's strange that I can view information from my firebase database and I can display information on my website.. 
function toggleSignIn() {
  if (firebase.auth().currentUser) {
    // [START signout]
    firebase.auth().signOut();
    // [END signout]
  } else {
    var email = document.getElementById('email').value;
    var password = document.getElementById('password').value;
    if (email.length < 4) {
      alert('Please enter an email address.');
      return;
    }
    if (password.length < 4) {
      alert('Please enter a password.');
      return;
    }
    // Sign in with email and pass.
    // [START authwithemail]
    firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      // [START_EXCLUDE]
      if (errorCode === 'auth/wrong-password') {
        alert('Wrong password.');
      } else {
        alert(errorMessage);
      }
      console.log(error);
      //document.getElementById('quickstart-sign-in').disabled = false;
      // [END_EXCLUDE]
    });
    // [END authwithemail]
  }
}

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

Jacob Wenger

unread,
Sep 22, 2016, 6:30:40 PM9/22/16
to fireba...@googlegroups.com
Hey there,

Just for kicks, try upgrading to the latest SDK version (3.4.0) and see if that still shows the issue. If it does, please open up the developer tools, check out the Network tab, find the failing auth request, and see if you can grab the exact response JSON that is being sent. Other things I can think of are to make sure you don't have any sort of firewall set up which is blocking requests.

Cheers,
Jacob

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/ad69c716-0aad-4af6-ab9f-dfbb27707bd7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Bassam

unread,
Sep 23, 2016, 4:04:27 AM9/23/16
to Firebase Google Group
Hey Lucas,
Just tested signInWithEmailAndPassword with the following userAgent:
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.89 Safari/537.36"
It worked as expected.
The network log you attached does not show the status of the response.
Did you try testing in a different browser, device? Does this only happen when you are using reactJS?

Bassam


On Thursday, September 22, 2016 at 6:34:02 PM UTC-7, lrenc...@uc.cl wrote:
Hi Jacob!

Thank you for your reply, I tried updating to the latest SDK, but still the error persists. I'm attaching a picture of the request.

Don't know if there is a problem with the POST method and ReactJS?

Best,
Lucas

To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

Jacob Wenger

unread,
Sep 23, 2016, 12:01:25 PM9/23/16
to fireba...@googlegroups.com
Hey Lucas,

Can you send us the exact response JSON for that request. You should be able to find it in the "Response" tab in the tab menu right above the image you sent in. Here is what I'm talking about:


Cheers,
Jacob

To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

lrenc...@uc.cl

unread,
Sep 24, 2016, 8:15:30 AM9/24/16
to Firebase Google Group
Hi Jacob

My response window was blank, saying "Failed to load response data".


I added a 
function toggleSignIn(event) {
  event.preventDefault();

....

and now it works sometimes... I click submit and for 3 times it would say I'm not logged, and in the fourth, it does log me in. Why can this be happening?

Thanks!
Lucas


On Friday, September 23, 2016 at 1:01:25 PM UTC-3, Jacob Wenger wrote:
Hey Lucas,

Can you send us the exact response JSON for that request. You should be able to find it in the "Response" tab in the tab menu right above the image you sent in. Here is what I'm talking about:


Cheers,
Jacob

lrenc...@uc.cl

unread,
Sep 24, 2016, 8:15:49 AM9/24/16
to Firebase Google Group
Hi Bassam

I added this to my code:

function toggleSignIn(event) {
 
event.preventDefault();
....

When I try once to log in, sometimes it works in the first try, and sometimes it logges me in in the second or third try. Why do you think this could be happening?

After the method: 
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
      // Handle Errors here.
      var errorCode = error.code;
      var errorMessage = error.message;
      // [START_EXCLUDE]
      if (errorCode === 'auth/wrong-password') {
        alert('Wrong password.');
      } else {
        alert(errorMessage);
      }
      console.log(error);
      // [END_EXCLUDE]
      
    });

if (firebase.auth().currentUser){
   //window.location = '/admin';
   alert('Login!');
  }
  else {
   //window.location = '/';
   alert('No Login');
  }

I'm trying to do see if the user is really authenticated, and later I could redirect to another page. Maybe there's a problem that reactJS try to run the first method and meanwhile continue with the other one? How can I set something to wait until the signInWithEmailAndPassword is completed?

Best,
Lucas!

lrenc...@uc.cl

unread,
Sep 24, 2016, 8:15:49 AM9/24/16
to Firebase Google Group
Hi Bassam,

I tried the signInWithEmailAndPassword in a pure javascript app and it worked perfectly. But it seems theres a problem with reactJS? I tried in firefox and safari, both have the same error..

Best
Lucas 


On Friday, September 23, 2016 at 5:04:27 AM UTC-3, Bassam wrote:

Bassam

unread,
Sep 25, 2016, 11:08:01 PM9/25/16
to Firebase Google Group
You seem to be checking synchronously for the currentUser state. You need to use an onAuthStateChanged listener to determine the auth state before deciding whether to login or not: https://firebase.google.com/docs/auth/web/manage-users
This is the proper way to do it. That could be the reason for the flakiness you are experiencing.
Reply all
Reply to author
Forward
0 new messages