title: Nuxt.js with passport losing req.user
body: <p>I'm trying to make Node.js app with Nuxt.js and Passport.js.
  I login and set user data in vuex.</p>
  
  <p>action:</p>
  
  <pre><code>nuxtServerInit ({ commit }, { req }) {
      if (req.session &amp;&amp; req.session.authUser) {
          commit('SET_USER', req.session.authUser)
      }
  }
  </code></pre>
  
  <p>mutation:</p>
  
  <pre><code>SET_USER: function (state, user) {
      state.authUser = user
  }
  </code></pre>
  
  <p>And it works fine, but when I tried to access page that can be accessed only by loged in user there came problems.</p>
  
  <pre><code>axios.get('http://localhost:3000/api/articles/add')
  
  router.get('/api/articles/add', ensureAuthenticated,
   (req, res) =&gt; {
      res.send({
          title: 'Add Article'
      })
  })
  
  function ensureAuthenticated (req, res, next) {
      if (req.isAuthenticated()) {
          return next()
      } else {
          res.redirect('/users/login')
      }
  }
  </code></pre>
  
  <p>I login and go to <a href="http://localhost:3000/articles/add" rel="nofollow noreferrer">http://localhost:3000/articles/add</a>, make request for data restricted for this user (GET <a href="http://localhost:3000/api/articles/add" rel="nofollow noreferrer">http://localhost:3000/api/articles/add</a>). Checking by <code>ensureAuthenticated</code> if user is loged in and <code>isAuthenticated()</code> returns <code>false</code> all the time and when I want to send user data without <code>ensureAuthenticated</code> it's returning <code>undefined</code></p>
  
  <pre><code>app.get('/api/articles/add', (req, res) =&gt; {
      res.send(req.user) // undefined
  })
  </code></pre>
  
  <p>BUT if I will send this data to the same api route as page, which I want access, I'm getting right data on screen.</p>
  
  <pre><code>app.get('/articles/add', function(req, res) {
      res.send(req.user) // {...}
  })
  </code></pre>
  
  <p>Can someone explain me that? And in some situation I can't make redirection from node.js side. Like in this prev example </p>
  
  <pre><code>function ensureAuthenticated (req, res, next) {
      if (req.isAuthenticated()) {
          return next()
      } else {
          res.redirect('/users/login') // ignored
      }
  }
  </code></pre>