title: Pushing user data from Nodejs server to Angular after successful login
body: <p>I try to login my user via Facebook with use of PassportJS and pass the user data to Angular.
  On the server side it all looks ok with the following code for the Facebook callback in users controller:</p>
  
  <pre><code>exports.facebookCallback = function() {
  return function(req, res, next) {
      passport.authenticate('facebook', function(err, user, email) {
          if (err || !user) {
              return res.redirect('/auth');
          }
          req.login(user, function(err) {
              if (err) {
                  return res.redirect('/auth');
              }
              return res.redirect('/');
          });
      })(req, res, next);
   };
  };
  </code></pre>
  
  <p>From what I understand from the PassportJS docs, calling req.login should put user data into the session.</p>
  
  <p>My routes on the server side looks following:</p>
  
  <pre><code>app.get('/auth', usersCtrl.auth);
  app.get('/auth/signout', usersCtrl.logout);
  app.get('/auth/facebook', passport.authenticate('facebook', {
      scope: ['email', 'user_hometown']
  }));
  app.get('/auth/facebook/callback', usersCtrl.facebookCallback());
  </code></pre>
  
  <p>express and passport configuration includes:</p>
  
  <pre><code>app.use(express.cookieParser());
  app.use(express.session({secret: '1234567890QWERTY'}));
  app.use(express.bodyParser());
  app.use(passport.initialize());
  app.use(passport.session());
  </code></pre>
  
  <p>Now on the angular side I try to get the user data from the session in a service defined like this:</p>
  
  <pre><code>module.exports = require('angular')
  .module('HomeModule', [])
  .controller('HomeCtrl', function ($scope) {
         //home controller code ors here
  }).controller('NavbarCtrl', ['$scope', 'Authentication', function ($scope, Authentication) {
      $scope.authentication = Authentication;
      //rest of the navbar controller goes here
  }]).factory('Authentication', [
      function() {
          var _this = this;
  
          _this._data = {
              user: window.user
          };
  
          return _this._data;
  
      }
  ]);
  </code></pre>
  
  <p>Unfoortunately, the user data is not available in window.user on angular side. 
  Any ideas what I'm doing wrong here?</p>