title: How to update req.user session object set by passportjs?
body: <p>I'm trying to do this since a lot of days but all my tests fails...</p>
  
  <p>Users on my platform connect them by using passportjs strategies (paypal, facebook, google...).</p>
  
  <p>When the user is connected I write his nickname on the right in the header.
  The html code of the header is generated from a handlebars template, and when this partial is served by expressjs, I send the req.user session object to the template in order to write nickname and other informations...</p>
  
  <p>By the way, this works great but I have a problem when the user update his nickname from his profile, I can't update session object on the server side and if the user reload the page, the old nickname appears again.</p>
  
  <p>And I don't want to request user informations from DB every time a user load a page, so i want to keep this config :</p>
  
  <pre><code>// -- Passport session setup
  passport.serializeUser(function(user, done) { done(null, user); });
  passport.deserializeUser(function(obj, done) { done(null, obj); });
  </code></pre>
  
  <p>My middleware to set locals :</p>
  
  <pre><code>// -- Set accessible datas from the template
  res.locals = _.extend(res.locals, {
      user: req.user,
      query: req.url,
      title: app.config.title,
      url: app.config.url
  });
  </code></pre>
  
  <p>My fails :</p>
  
  <pre><code>// Trying to update req.user directly : not persistent
  req.user.nickname = User.get('nickname');
  
  // Trying to update passport session : exception error
  req.session.passport.user = User.toJSON();
  
  // Trying to replace full session object : not persistent
  var session = req.session;
  session.passport.user = User.toJSON();
  req.session = session;
  </code></pre>
  
  <p>Any suggestion ?</p>
  
  <p>For moment, only a logout then a login works... It's not really efficient :)</p>
  
  <p><strong>EDIT</strong> : </p>
  
  <pre><code>// Application router
  var Router = require('./helpers/router.js');
  
  // Create Express Server
  var app = express().http().io();
  
  // -- Init app router
  var router = new Router(app);
  
  // -- Framework Middleware
  app.use(router.middleware); 
  
  #########################
  /***
   * APP ROUTER
   **/
  
  // Export router
  module.exports = function(app) {
  
      // Set instance
      var router = this;
  
      // Returns routes register &amp; middleware methods
      return {
  
          // -- Register routes
          register: function() {
              requirejs(['routes'], function(routes) {
                  _.each(routes, function(name, route) {
                      app.get(route, function(req, res, next) {
                          requirejs(['views/'+name], function(view) {
                              if ( view ) {
                                  var _view = new view(_.extend(req.params, {server: {req: req, res: res, next: next}})); 
                                  _view.render(name, req, res, next); 
                              }
                              else {
                                  next();
                              }
                          }, function (err) {
                              console.log('error' + err)
  
                          });
                      }); 
                  });
              });
          },
  
          // -- Bind middleware
          middleware: function(req, res, next) {
  
              // Get the current path
              console.log("Middleware :: "+req.url);
  
              // Add user informations
              res.locals = _.extend(res.locals, {
                  user: req.user,
                  query: req.url,
                  title: app.config.title,
                  url: app.config.url
              });
  
              // Go next 
              next(); 
  
          }
      }
  }
  </code></pre>