Search code examples
javascriptfirebasefirebasesimplelogin

Authenticating Users with Email & Password error


Im trying to create a mail and password user to firebase, but im kepp getting this error:

Error: The browser redirected the page before the login request could complete. {code: "REQUEST_INTERRUPTED", stack: (...), message: "The browser redirected the page before the login request could complete."}

var ref = new Firebase("https://***.firebaseio.com");
$('.btn').click(function() {
   var mail = $('#inputEmail3').val();
   var pass = $('#inputPassword3').val();
   ref.createUser({
       email : mail,
       password : pass
    }, function(error) {
       if (error === null) {
        console.log("User created successfully");
       } else {
        console.log("Error creating user:", error);
       }
   });
});

$(document).ready();

Solution

  • If the element you are selecting with the $('.btn') selector is a link the browser will navigate to the linked page before the asynchronous ref.createUser function completes. To prevent this, add a return false statement to the end of the click event handler. You can also add an e.preventDefault() statement at the top of the click handler which will ensure that the link navigation does not occur as shown below.

    $('.btn').click(function(e) { //Add the 'e' event object to the parameters
        e.preventDefault() //Prevents navigation (the default link click action)
        var mail = $('#inputEmail3').val();
        var pass = $('#inputPassword3').val();
        ref.createUser({
            email : mail,
            password : pass
        }, function(error) {
           if (error === null) {
            console.log("User created successfully");
           } else {
            console.log("Error creating user:", error);
           }
       });
       return false; //Extra insurance
    });