title: Node.js 'headers already sent' when page is refreshed
body: <p>I keep getting this error (after a certain amount of time) when i refresh the my 'members area' after login. I use response.redirect to redirect to the area (success) or back to sign in form (error). How can i fix this?</p>
  
  <pre><code>app.get('/sellers/login', function(request, response) {
      if(request.session.sellerId){
          response.redirect( '/sellers/area?logged_in=true');
      }
      else{
          response.render('pages/sellers-login');
      }
  });
  
      app.post('/authenticate', function(request, response) {
      if(request.session.sellerId){
          response.redirect('/area?logged_in=true');
      }
      else{
          db.authenticate(request.body.loginid, function(err, results) {
          if(err){ 
              response.redirect('/sellers/login?err=1&amp;logged_in=false&amp;type=db');
          }
          else{
              if(results.length &gt;=1){
                  var hash = results[0]['hash'];
                  var seller_id = results[0]['id'];
                  bcrypt.compare(request.body.password, hash, function(err, res) {
                      if(res){
                          request.session.sellerId = seller_id;
                          response.redirect('/sellers/area?logged_in=true');
                      }
                      else{
                          response.redirect('/sellers/login?err=1&amp;logged_in=false&amp;type=pMatch');
                      }
                  });
              }
              else{
                  response.redirect('/sellers/login?err=1&amp;logged_in=false&amp;type=user');
              }
          }
  
          });
      }
  
  });
  app.get('/sellers/area', function(request, response) {
      if(request.session.sellerId){
          response.render('pages/sellers-area');
      }
      else{
          response.redirect('/sellers/login?not_logged_in=true');
      }
  
  });
  </code></pre>