title: Firebase onAuthStateChanged unsubscribe recursion
body: <p>I have this code that checks to see if a user is already signed in in Firebase, if so, use Redux to dispatch an action and update the state to the current auth user.</p>
  
  <pre><code>/**
   * check to see if the user has signed in already or not
   */
  function initAuth(dispatch) {
    return new Promise((resolve, reject) =&gt; {
      const unsubscribe = firebase.auth().onAuthStateChanged(
        authUser =&gt; {
          dispatch({ type: "INIT_AUTH", payload: authUser });
          unsubscribe();
          resolve();
        },
        error =&gt; reject(error)
      );
    });
  }
  initAuth(store.dispatch)
    .then(() =&gt; render())
    .catch(error =&gt; console.error(error));
  </code></pre>
  
  <p>What I am confused is, why is the unsubscribe() called within the unsubscribe? I know you can do this as in JavaScript recursion, but what's the use here? Thanks!</p>