0
votes

My web application is using Firebase and I am using Email/Password as Sign-in method for my application.issue is when my form is inside <form></form> tag i am getting auth/network-request-failed error.Authentication works fine if i change form to div.
Steps I followed
Step 1: Enabled Email/Password Sign-in method enter image description here

Step 2: Added a dummy user enter image description here

Step 3:Here is my authentication function

function authenticateUser() {
    var email = document.getElementById("email").value;
    var password = document.getElementById("password").value;

    firebase.auth().signInWithEmailAndPassword(email, password).catch(function (error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        if (errorCode === 'auth/wrong-password') {
            alert('Wrong password.');
        }
        else if (errorCode = 'auth/network-request-failed') {
            alert('Network error.');
        } else {
            alert(errorMessage);
        }
        console.log(error);
    });
}

Step 4 :my login form

<form class="form-signin">
                        <h1>Login to Your Account</h1>
                        <label for="inputEmail" class="sr-only">Email address</label>
                        <input type="email" id="email" class="form-control" placeholder="Email address" required="" autofocus="">
                        <label for="inputPassword" class="sr-only">Password</label>
                        <input type="password" id="password" class="form-control" placeholder="Password" required="">
                        <div class="checkbox">
                            <label><input type="checkbox" value="remember-me"> Remember me</label>
                        </div>
                        <button id="login" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
                    </form>

Before asking you people i checked the Firebase Documentation and samples on github and ofcourse googled a lot.

Please help me.

1
Anybody found a working solution for this? - obai

1 Answers

0
votes

it can be caused by authentication state try to type manually your email and password and

firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
    var errorCode = error.code;
    var errorMessage = error.message;
    console.error({ ErrorCode: errorCode, ErrorMessage: errorMessage });
});