title: Firebase, Avoid Logged-in user to visit login page
body: <p>I am using firebase hosting to make an app.
  I have following code in my login.html page.</p>
  
  <pre><code>    &lt;script&gt;
  
          $(document).ready(function() {
                  firebase.auth().onAuthStateChanged(function(user) {
                  if (user) {
                      // user is loggin redirect to dashboard
                  } else {
                      // No user is signed in. keep them here
                  }
                  });
          });
  
   $("#loginbtn").on("click",()=&gt;{
                  console.log("login");
                  var errormessage="";
                  var email = $("#email").val();
                  var password =  $("#password").val();
  
                  //client validate
                  if(email.length == 0)
                  errormessage+=("Enter a valid email.&lt;br&gt;");
                  if(password.length == 0)
                  errormessage+="Enter a valid password.&lt;br&gt;";
                  if(errormessage.length==0){
                      $("#loginbtn").prop('disabled', true);
                      firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
                      // Handle Errors here.
                      var errorCode = error.code;
                      var errorMessage = error.message;
                      $("#loginbtn").prop('disabled', false);
                      showMessage(errorMessage);
                      // ...
                      });
  
  
                  }else{
                      $("#signupbtn").prop('disabled', false);
                      showMessage(errormessage);
                  }
  
  
              })
      &lt;/script&gt;
  </code></pre>
  
  <p>However when user is logged in and user explicitly try to visit login.html by puting that in address bar the <strong>login page is being displayed for few seconds</strong> and then it redirects to dashboard page.
  This leaves a bad user experience as login form is displayed for few seconds.
  How can i acheive something like php sessions? where page redirects without rendering?
  Can we connect cloud functions using "rewrites" to redirect user to other pages from backend? can a cloud function find if user is logged-in or not on client side?</p>
  
  <p>(1) user Login with <code>signInWithEmailAndPassword()</code>.<br>
  (2) <code>AuthState</code> listener redirects to home url.<br>
  (3) user try to visit login.html page again.<br>
  (4) login.html page gets displayed for few seconds. <strong>&lt; problem.</strong><br>
  (5) <code>AuthState</code> listener redirects to home url.<br></p>