title: Passport.js Session Confusion
body: <p>I am learning node and express. I am trying to build a very basic app that will simply let a user log in using json. Then will maintain session until they log out. With asp.net this is a doddle you just set it up in the config and call...</p>
  
  <pre><code>Auth.Login(username,pasword)
  </code></pre>
  
  <p>When they log out you just do:</p>
  
  <pre><code>Auth.logout()
  </code></pre>
  
  <p>And if you need to check if they are logged in you simply do:</p>
  
  <pre><code>Auth.IsLoggedIn()
  </code></pre>
  
  <p>Or code to that effect. Well seems like Passport for node is just not that simple. I spent all night getting this working...</p>
  
  <pre><code>app.post('/authentication/login', function handleLocalAuthentication(req, res, next) {
  
      passport.authenticate('local', function(err, user, info) {
  
          // Manually establish the session...
          req.login({username:'me@me.com',password:'password'}, function(err) {
              if (err) return next(err);
              return res.json({
                  message: 'user authenticated'
              });
          });
  
      })(req, res, next);
  });
  
  app.get('/authentication/isauthenticated',function(req,res){
  
      console.log(req.isAuthenticated());
  
  })
  
  passport.use(new LocalStrategy(
      function(username, password, done) {
  
          return done(null, {username:'ss',password:'sffds'});
      }
  ));
  </code></pre>
  
  <p>So now I have no cookies, no session persisted when I login and then hit the <code>/authentication/isAuthenticated</code> url. I can't even get a breakpoint to stop in the strategy...</p>
  
  <pre><code>passport.use(new LocalStrategy(
      function(username, password, done) {
  
          console.log('ggg');
          return done(null, {username:'ss',password:'sffds'});
  
      }
  ));
  </code></pre>
  
  <p>Am I looking at the wrong solution for this? Should I be rolling my own auth or something with a basic middleware function?</p>