Why is Firebase Auth reloading the page when signing in?

Viewed 625

I'm setting up the login page for a new web-app I'm developing. I'm using Framework 7 with Google Firebase. The problem is that when I click the "login" button, Firebase returns in nothing... it just reloads the page, even if the user and password are okay.

I've tried to take a look to the errors the function might throw (using the dev console) but it results in nothing (as I say, the page just reloads).

This is my javascript login function:

function login() {
    var formData = app.form.convertToData('#login-form');

    firebase.auth().signInWithEmailAndPassword(formData.username, formData.password).then(function () {
        mainView.router.navigate({name: 'dashboard'});
    }).catch(function (error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        console.log(`[${errorCode}] ${errorMessage}`);

        $('#login-error').html(errorMessage);
    });
}
1 Answers

This might not be your issue, but for me, the reason was that I forgot to prevent the default behavior of my login button. For example, for me, what solved it was this:

$("#login-button").click(e => {
  e.preventDefault();
  login();
});

I hope that helps :)

Related