title: Node.js redirect to login if user is not logged in
body: <p>I am using the <a href="https://github.com/braitsch/node-login" rel="nofollow">node-login</a> module to login on my website. Ok, after the user logs in I render my dashboard.html website:</p>
  
  <pre><code>app.get('/', function(req, res){
  // check if the user's credentials are saved in a cookie //
      if (req.cookies.user == undefined || req.cookies.pass == undefined){
          res.render(req.locale+'/login', { title: 'Hello - Please Login To Your Account' });
      }   else{
  // attempt automatic login //
          AM.autoLogin(req.cookies.user, req.cookies.pass, function(o){
              if (o != null){
                  req.session.user = o;
                  res.redirect('/home');
              }   else{
                  res.render('/login', { title: 'Hello - Please Login To Your Account' });
              }
          });
      }
  });
  </code></pre>
  
  <p>After that, all other html websites are linked from within dashboard.html, so there are no other app.get methods called.</p>
  
  <p>If a user tries to navigate to <a href="http://www.example.com/news.html" rel="nofollow">http://www.example.com/news.html</a> (or any other html page that is not the login page ), if the user is not logged in, I need to redirect him to the login page.</p>
  
  <p>I first thought somehting like this but I don't know if this is possible:</p>
  
  <pre><code>app.get('I-don't-know-what-to-insert-here', function(req, res) {
      if (req.session.user == null){
  // if user is not logged-in redirect back to login page //
          res.redirect('/');
      }   else{
          res.redirect('redirect-here-to-the-requested-html-page')  
      }
  });
  </code></pre>
  
  <p>Regards,</p>