title: Express change session every request
body: <p>I have a function to login</p>
  
  <pre><code>app.post('/doLogin', function(req,res){
          db.users.findOne({username: req.body.username}, function(err, user) {
              if( err ) {
                  console.log("Login fail");
              } 
              else if (user != null) {
                  if (req.body.password == user.password) {
                      req.session.user_role = "user";
                      req.session.save();
              } else {
                  req.session.user_role = "null";
                  console.log("Wrong login");
              }
          }
          res.send({redirect: "/"});
      });
  
  });
  </code></pre>
  
  <p>This function is used to save a variable into session <code>req.session.user_role = "user";</code>
  But when the new request to check user logged in or not</p>
  
  <pre><code>app.get('/', function(req,res){
      redis.get('sess:' + req.session.id, function(err, result){
          console.log("Get session: " + util.inspect(JSON.parse(result),{ showHidden: true, depth: null }));
      });
      if ((req.session.user_role == "user")) {
            console.log("Logged in");
      } else {
          console.log("Logged out");
      }
  });
  </code></pre>
  
  <p>Then return always is "Logged out", because the session is changed. I use Redis to store session, I think it is Redis fault because when I stop using Redis, it's OK
  Please help me!</p>