title: Firebase Authentication works but keeps on refreshing the page
body: <p>So I am new to web development and Firebase as well. I have been trying to build a multi page web app in simple javascript and firebase. App looks good and works for most of the part. Yet it is really of no use as I am having following issue :</p>
  
  <ol>
  <li>When I sign in through googleAuthProvider (on my index.html page), I am taken to another page which is main.html . Now til here is fine. But once the main.html is loaded, it goes into a loop of continuous refreshing. </li>
  </ol>
  
  <p>My rationale behind this is, that somehow Firebase is trying to re-authenticate the page on loading. And so the loop happens. But why, this I am not able to debug.</p>
  
  <p>I have looked over almost everything I could find on internet but no where I could find a solution which is for simple javascript based multi page web app with firebase.</p>
  
  <p>Here's a link to my app if anyone is interested and kind enough to have a look.</p>
  
  <p><a href="https://kaushikdev.github.io/ChatBot" rel="nofollow noreferrer">Chatbot</a></p>
  
  <p>Also, here is my javascript code too.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var config = {
      apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      authDomain: "XXXXXXXXX.firebaseapp.com",
      databaseURL: "https://XXXXXXXX.firebaseio.com",
      projectId: "XXXXXXXXXX",
      storageBucket: "XXXXXXXXXX.appspot.com",
      messagingSenderId: "XXXXXXXXXXXX"
    };
    firebase.initializeApp(config);
  
  //===============================================================================================
  $("document").ready(function(){
  
  const signinGoogle = document.getElementById("googleAuth");
  const signOut = document.getElementById("signout");
  const sendMsg = document.getElementById("send");
  const messageBox = document.getElementById("chatBox");
  const displayNAME = document.getElementById("dipslayName");
  const storageRef = firebase.storage().ref();
   
  var currentUser;
  var name;
  var photoUrl;
  
   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
   initApp();
   //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if(signinGoogle){
     googleAuth.addEventListener('click', e=&gt;{
     firebase.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider()).then(function(result) {  
     // This gives you a Google Access Token. You can use it to access the Google API.
       var tokenGoogle = result.credential.accessToken;
       // The signed-in user info.
       var userGoogle = result.user;
       // ...Below line to be rmeooved if not working expectedly.
      // var user = firebase.auth().currentUser;
     }).catch(function(error) {
       // Handle Errors here.
       var errorCode = error.code;
       var errorMessage = error.message;
       // The email of the user's account used.
       var email = error.email;
       // The firebase.auth.AuthCredential type that was used.
       var credential = error.credential;
       // ...
     });
     });
    
    }
   //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     if(signOut){
            signout.addEventListener('click', e=&gt;{
       
      if(confirm("Do you wish to leave?")){
      promise = firebase.auth().signOut().then(function(){
      window.location = "index.html";
      });
      promise.catch(e =&gt; 
            console.log(e.message))
      } 
     
     });
     }
  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      function initApp(){
      firebase.auth().onAuthStateChanged(function(user){
      
     if(user){
     window.location = "main.html";
    
     $("document").ready(function(){
      
     currentUser  = firebase.auth().currentUser;
            name  = currentUser.displayName;
     photoUrl = currentUser.photoURL ;
      
     console.log("Current user's name is : "+name);
     console.log("Current user's photoUrl is : "+photoUrl);
           
     displayNAME.innerHTML = "Hi "+name;
     
      //+++++++++++Retrieving Msgs++++++++++++++++++++++++++++++++
      var i=1; 
      var firebaseRetrieveRef = firebase.database().ref().child(name+uid+"/MessageBoard");
      firebaseRetrieveRef.on("child_added", snap =&gt;{
      var retrievedMsg = snap.val();
      console.log("retrieved msgs is : "+retrievedMsg);
      $("#taskList").append("&lt;li id='list"+i+"'&gt;&lt;div style='width:100%'&gt;&lt;img src='"+photoUrl+"'style='width:10px;height:10px;border-radius:5px;'/&gt;&lt;label&gt;"+name+"&lt;/label&gt;&lt;/div&gt;&lt;div style='width:100%'&gt;&lt;p&gt;"+retrievedMsg+"&lt;/p&gt;&lt;/div&gt;&lt;/li&gt;");
      i++;
       });
   //+++++++++++Storing Msgs++++++++++++++++++++++++++++++++
    $("#send").on("click", function(){
      var newMessage=messageBox.value;
       if(newMessage==""){
       alert("Empty Message doesn't make any sense, does it?? ");
       }
       else{
       var firebaseStoreRef = firebase.database().ref().child(name+uid+"/MessageBoard");
      firebaseStoreRef.push().set(newMessage);
                messageBox.value="";
       }
     });
   //+++++++++++Clearing/deleting all tasks++++++++++++++++++++++++
    $("#clear").on("click", function(){
       var firebaseDeleteRef  = firebase.database().ref().child(name+uid+"/MessageBoard");
       firebaseDeleteRef.remove();
       $( ".scrolls" ).empty();
       });
      //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
   
     });
                  }
    else
    {
    console.log(user+" is not logged in");
    }
    
    });
      } 
       
  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   });</code></pre>
  </div>
  </div>
  </p>