title: Why is firebase throwing a permission error after sign-out?
body: <p>In a react-native application, dispatching an action that invokes firebase-auth to sign-out ends in a firebase permission error:</p>
  
  <p><a href="https://i.stack.imgur.com/Z1937.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z1937.png" alt="enter image description here"></a></p>
  
  <p>Here's the method inside the drawer component that dispatches the action:</p>
  
  <pre><code>logout = () =&gt; {
          this.props
              .logoutUser()
              .then(() =&gt; {
                  this.props.navigation.navigate('Login');
              })
              .catch((err) =&gt; alert(err));
      };
  </code></pre>
  
  <p>and here's the <code>logout</code> action:</p>
  
  <pre><code>export const logoutUser = () =&gt; {
      return (dispatch) =&gt; {
          return new Promise((resolve, reject) =&gt; {
              firebase
                  .auth()
                  .signOut()
                  .then(() =&gt; {
                      dispatch({ type: types.RESET_APP });
                      console.log('Dispatching types.RESET_APP');
                      resolve();
                  })
                  .catch((error) =&gt; reject(error.message));
          });
      };
  };
  </code></pre>
  
  <p>When executed, the screen reverts back to the login screen as desired. Console logs <code>Dispatching types.RESET_APP</code>, and THEN the error above displays. </p>
  
  <p>authStateChanged Listener in my login:</p>
  
  <pre><code>export const loginUser = (email, password) =&gt; {
      return (dispatch) =&gt; {
          dispatch({ type: types.LOGIN_USER });
          // listen for change in auth state before signing in
          return new Promise((resolve, reject) =&gt; {
              firebase
                  .auth()
                  .signInWithEmailAndPassword(email, password)
                  .then((userCredential) =&gt; {
                      console.log('User Credential: ' + JSON.stringify(userCredential));
                      const unsubscribe = firebase.auth().onAuthStateChanged((user) =&gt; {
                          if (user) {
                              console.log('Logged in: ' + user.email);
                              loginUserSuccess(dispatch, user);
                              resolve(user);
                          } else {
                              console.log('Authentication state changed, user object is null...');
                              //resetAuth();
                          }
                      });
                      // No longer need to listen to auth state
                      unsubscribe();
                  })
                  .catch((error) =&gt; {
                      console.log('Error during Email sign-in: ' + error);
                      loginUserFail(dispatch, error.message);
                  });
          });
      };
  };
  </code></pre>
  
  <p>auth state observer is unsubscribed in the login function, so whats causing this?</p>