Bug auth/network-request-failed

585 views
Skip to first unread message

Phuc Vo

unread,
Nov 25, 2016, 10:52:02 AM11/25/16
to Firebase Google Group
I had read some topic, it says this bug had resolved with 3.2 but not i use 3.5 and 3.6 . I had read some toipc and i had removed type="submit" in form and add domain in project but it always reports . I had tested it with Firefox 50 and Chrome 54 - I create it in web. My flow is: i call ajax and receive data - If data is true, it will return json include token and sucess = 1. After Ajax call, if have data and data.sucess = 1, i will auth with data.token

<form id="form-login" action="" enctype="application/x-www-form-urlencoded">
<!-- Username -->
   
<input id="username" name="username" type="text" size="20"  />
<!-- Password -->
   
<input id="password" name="password" autocomplete="off" type="password" size="20"  />
<input id="btn-login" class="h_submit" value="Login" />

$('#btn-login').click(function(event) {
       
event.preventDefault();

       
var username = $.trim(jInputUsername.val());
       
var password = $.trim(jInputPassword.val());
       
if (!username || !password) {
            alert
("Error");
       
} else {

            $
.ajax({
                url
: '',
                type
: "post",
                data
: {'username': username, 'password': password},
                success
: function(data, textStatus, jqXHR) {
                   
//        
                   
if ($.isPlainObject(data)) {
                       
//    On error
                       
if (data && data.succeed) {
                            firebase
.auth().signInWithCustomToken(data.token).catch(function(error) {
                             
var errorCode = error.code;
                             
var errorMessage = error.message;
                             
if (errorCode === 'auth/invalid-custom-token') {
                                alert
('Token problem.');
                             
}
                              alert
(errorMessage);
                           
});
                           
var fullHref = decodeURIwindow.location.href);
                            setTimeout
(window.location.href = fullHref.replace(hash, ''), 1000);
                       
}
                   
}
               
},
                error
: function( jqXHR, textStatus) {
                    console
.log('Username or passord wrong");
                }
                , dataType:'
json'
            });
        }
    });


Bassam

unread,
Nov 27, 2016, 4:01:54 AM11/27/16
to Firebase Google Group
Hey Phuc Vo, I am not sure I understand what exactly is going on. I did notice in your code you are setting a timer to redirect on success. This could interrupt the flow and network request. It is better to wait for the signInWithCustomToken to resolve before redirecting:
firebase.auth().signInWithCustomToken(data.token).then(function(user) {
  // redirect here.
}).catch(function(error) {
  // catch error here.
});
Reply all
Reply to author
Forward
0 new messages