bigtunacan (16) [Avatar] Offline
#1
In listing 9.7 - page 260 there is a check if the user is found which redirects to the root URL, but does not reset the session user ID. It seems one would want to reset the session userId to null even when the user is not found?

   // Existing code
    User.findOne(req.session.userId, function foundUser(err, user){
      if(err){ return res.negotiate(err); }
      if(!user){
        sails.log.verbose('Session refers to a user who no longer exists.');
        return res.redirect('/');
      }

      req.session.userId = null;
      return res.redirect('/');
    });



   // Proposed code
    User.findOne(req.session.userId, function foundUser(err, user){
      if(err){ return res.negotiate(err); }
      if(!user){
        sails.log.verbose('Session refers to a user who no longer exists.');
      }

      req.session.userId = null;
      return res.redirect('/');
    });
283876 (35) [Avatar] Offline
#2
Thanks! I've made the correction. Best, Irl