title: Can't set headers after they are sent. Express JS
body: <p>Help me :(, i cannot find solution for my error, i try using return before my response it dosen't work</p>
  
  <p><a href="https://i.stack.imgur.com/uk1uN.png" rel="nofollow noreferrer">this my code</a></p>
  
  <pre><code>function isAuthenticated(req, res, next) {
  var getToken = req.cookies.token;
  var getUrl = req.originalUrl;
  console.log(getToken)    
  if(getToken == undefined) {
      res.redirect('/login')
      next()
  } else {
      console.log('success')
      next()
  }
  next() }
  
  router.get('/login', isAuthenticated, auth.login);
  router.get('/logout', isAuthenticated, auth.logout);
  router.post('/logging', auth.prosesLogin);
  </code></pre>