title: Trying to keep user logged in using firebase auth in reactjs
body: <p>I have a react app using firebase for authentication &amp; other tools. On a certain page, I check if the user is logged in using <code>firebase.auth().currentUser;</code> &amp; also tried with <code>firebase.auth().onAuthStateChanged</code> but it redirects me to the login page indicating I was not logged whereas I just logged in. </p>
  
  <p>Here is the code for what I have tried so far :</p>
  
  <pre><code>const [user, setUser] = React.useState(firebase.auth().currentUser);
  
    firebase.auth().onAuthStateChanged(function(user) {
      if (user) {
        setUser(user);
      }
    })
  
    React.useEffect(() =&gt; {
      firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
          setUser(user);
        }
      })
    });
  return(
  
      &lt;Styles&gt;
      { user ?
        &lt;Paper className={clsx(classes.root, "Paper")}&gt;
  
          &lt;div className="overlay"&gt;&lt;/div&gt;
  
          &lt;Container maxWidth="lg"&gt;
  
            &lt;HeaderTypography variant="h2" color="" gutterBottom&gt;
              Create an Event
            &lt;/HeaderTypography&gt; : &lt;Redirect to="/login"/&gt; }
  
  </code></pre>
  
  <p>Even after logging in, when I come to this page I still get redirected .. Any help will be welcomed </p>