title: React + Passport.js
body: <p><strong>TL;DR</strong> I'm making a MERN app and want to access the passport user from React. How?</p>
  
  <p>I'm trying to make a simple to-do app with the MERN stack and can't get user auth down. I'm using React on the front end with a proxy to an express api. I want to grab the <code>req.user</code> object from React so I can update the navbar based on whether the user is logged in or not. When I post to <code>/api/login</code> I can log the user object from the api route.</p>
  
  <p>React login form:</p>
  
  <pre><code>class Login extends Component {
  //..
    async login(event) {
      event.preventDefault();
      await api.login({
        username: this.state.username,
        password: this.state.password
      });
      this.setState({
        username: '',
        password: ''
      });
    }
  //..
  }
  </code></pre>
  
  <p>Axios:</p>
  
  <pre><code>export async function login({username, password}) {
    axios.post('/api/login', {username, password});
  }
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>router.post('/login', passport.authenticate('local'), helpers.login);
  
  exports.login = (req, res) =&gt; {
    res.json({ message: 'You have been logged in!' });
  };
  </code></pre>
  
  <p>From this <code>exports.login</code> function I can <code>console.log(req.user)</code> but when I try to access the user from any other route it is undefined.</p>
  
  <p>Here's what I want to do:</p>
  
  <p>React:</p>
  
  <pre><code>class App extends Component {
  //..
    componentDidMount() {
      this.isLoggedIn();
    }
  
    componentDidUpdate() {
      this.isLoggedIn();
    }
  
    async isLoggedIn() {
      const user = await api.isLoggedIn(); 
    }
  //..
  }
  </code></pre>
  
  <p>Which will make a request that returns the user object.</p>
  
  <p>I somewhat understand how the proxy may get in the way and how the session works but the pieces haven't clicked yet. Hoping someone can help me out.</p>
  
  <p><strong>EDIT</strong> So um... the problem just kinda went away. I'll update if something breaks again.</p>