Rahul Sharma
Rahul Sharma

Reputation: 358

Firebase in Web : A network error (such as timeout, interrupted connection or unreachable host) has occurred?

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
      console.log("Hurray ! signed in successfully !");
  } else {
    // No user is signed in.
     console.log("Sign in required !");
     $("#login-btn-nav").click();
  }
});



$("#login-btn").on('click',function(){
    console.log("Hello");
    var email = $("#email-input").val();
    var password = $("#password-input").val();

    if(email != "" && password != ""){
    		firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
				  // Handle Errors here.
				  var errorCode = error.code;
				  var errorMessage = error.message;
				  // ...
				  window.alert("Following error encountered : "+errorMessage+" .");
				});
    		}
});
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-messaging.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyDAvfWcdBTtmDbK7_aOkWFCRxNl1K4PDck",
    authDomain: "sarahhah-8e315.firebaseapp.com",
    databaseURL: "https://sarahhah-8e315.firebaseio.com",
    projectId: "sarahhah-8e315",
    storageBucket: "sarahhah-8e315.appspot.com",
    messagingSenderId: "965679781332"
  };
  firebase.initializeApp(config);
  console.log(config);
</script>
<script type="text/javascript" src="assets/js/login.js"></script>
copied the web code snipets ans pasted in the html code as attached and javascript code is also attached ! facing error as :

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

in web integration of firebase

thanks in advance for your cooperation

Upvotes: 4

Views: 5152

Answers (1)

kkost
kkost

Reputation: 3730

I will duplicate an answer from comments from Rahul Sharma because this saved me a lot of time. Hope this will help somebody else:

Use <div> instead of <form> tag

Upvotes: 7

Related Questions