I have the following code:

```
var config = {
       apiKey: "xxxxx",
       authDomain: "xxxxx",
       databaseURL: "xxxxx",
       projectId: "xxxxx",
       storageBucket: "xxxxx",
       messagingSenderId: "xxxxx"
};

firebase.initializeApp(config);

$("#loginButton").on('click', function(){
    logIn($("#email").val(), $("#pwd").val());
});

$("#logoutButton").on('click', function(){
   firebase.auth().signOut();
   console.log("clicked logout button");
});

function logIn(email, password){
   firebase.auth().signInWithEmailAndPassword(email,    password).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    alert(error.message);
  });
}

firebase.auth().onAuthStateChanged(function(user) {
    if (user) {
      console.log("Signed in");                  
      firebase.auth().currentUser.getIdToken(true).then(function(idToken) {
        // Send token to your backend via HTTPS
        // ...
        console.log("Token = " + idToken);
        console.log("Logged in!");
        $("#loginButton").val(idToken);
        $("#loginForm").submit();
      }).catch(function(error) {
           // Handle error
           console.log(error);
      });
   }
   else{
       console.log("User signed out");
   }
});

```

What I am trying to accomplish here is: The user fills the email and password fields, click on a button with `id="loginButton"`, I sign in, get the token id and send it to server (Is this form hackish way of sending it recommended?) and verify the token id through the Admin SDK in my express app (Node.js).

The point is. The user does sign in and sign out (By refreshing the page I can see that "Signed in" and "User signed out" are printed). 

**But why is `onAuthStateChanged` called only once when it should be observing/listening to every change on auth state?**

Why am I able to sign in and out but `onAuthStateChanged` is called only at the beginning (when page loads) and not called anymore upon button clicks (`loginButton` and `logoutButton`)?