title: req.user undefined when using $http with angularJS, express and passport
body: <p>I've run into a problem where <code>req.user</code> is undefined when making an API call with $http in angularJS.  The strange thing is that if I login with Postman and then make a call to my protected endpoint, <code>req.user</code> is defined and authentication is working as expected.  </p>
  
  <p>Protected endpoint <code>/activities</code> (this is where req.user is undefined when using $http):</p>
  
  <pre><code>var isAuthenticated = function (req, res, next) {
      if (req.isAuthenticated())
          return next();
      res.redirect(process.env.BASE_CLIENT_URL + 'login');
  }
  
  router.get('/activities', isAuthenticated, activityController.getActivities);
  </code></pre>
  
  <p>Angular Controller that I redirect to after a successful passport login, basically on load of this page I make a call to my <code>/activities</code> endpoint:</p>
  
  <pre><code>angular.module('myApp.view2', ['ngRoute'])
  
    .config(['$routeProvider', function ($routeProvider) {
      $routeProvider.when('/view2', {
        templateUrl: 'view2/view2.html',
        controller: 'View2Ctrl'
      });
    }])
  
    .controller('View2Ctrl', ['$scope', '$http', function ($scope, $http) {
  
      $scope.$on('$viewContentLoaded', function (event) {
        $http({
          method: 'GET',
          url: 'http://localhost:8000/api/activities',
          withCredentials: true
        }).then(function successCallback(response) {
          console.log("Success!");
        }, function errorCallback(response) {
          console.log("Error");
        });
      });
    }]);
  </code></pre>
  
  <p>Any thoughts?  I'm not sure why it would be working as expected through an API client such as Postman but not working in my angularJS app, am I missing certain headers?</p>
  
  <p>Thanks!</p>
  
  <p><strong>Update:</strong></p>
  
  <p><strong>Headers from $http request:</strong></p>
  
  <pre><code>accept:"application/json, text/plain, */*"
  accept-encoding:"gzip, deflate, br"
  accept-language:"en-US,en;q=0.9"
  cache-control:"no-cache"
  connection:"keep-alive"
  cookie:"connect.sid=s%3AFvUCnqkLyGKh6rZh41nU0oXDFiRpu3pZ.74Oit3DNmizkCyvGId1%2F%2FNbLQlichVM6HEHfh3MLS3g"
  host:"localhost:8000"
  pragma:"no-cache"
  referer:"http://localhost:8000/"
  user-agent:"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
  </code></pre>
  
  <p><strong>Headers from Restlet:</strong></p>
  
  <pre><code>{"params":{"headers":["Host: localhost:8000","Connection: keep-alive","User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36","Accept: */*","Accept-Encoding: gzip, deflate, br","Accept-Language: en-US,en;q=0.9","Cookie: [331 bytes were stripped]","If-None-Match: W/\"44faa272a8181008d08c6051967c5c38\""],"line":"GET /api/activities HTTP/1.1\r\n"},"phase":0,"source":{"id":819156,"type":1},"time":"496058853","type":159}
  </code></pre>
  
  <p>Might be an issue with the login when running it via the app.  If I login with Postman and THEN make the call to my <code>/activities</code> endpoint, it is successful.  However, performing the login and making the call to the <code>/activities</code> endpoint via my app is when I run into the issue.</p>