Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
NextJs redirect on previous page throws Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

I have 2 pages the lobby page and the room page, when i click a button in lobby it redirects me to the room page. Then, using getServerSideProps i check for some cookies and if they don't exists i want to redirect back to lobby page :

export async function getServerSideProps({req, params}) {
const cookie = JSON.parse(req.cookies.watchflix ?? null);
if( !cookie ){ 
    return {
        redirect: {
            destination: "/lobby",
            permanent: false,
          }
    };
}
return {
    props: {
        cookies: cookie
    },
};}

and it throws:

Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:561:11)
at NodeNextResponse.setHeader (H:\Projets\watchflix-client\node_modules\next\dist\server\base-http\node.js:59:19)
at DevServer.renderError (H:\Projets\watchflix-client\node_modules\next\dist\server\base-server.js:1165:17)
at DevServer.renderError (H:\Projets\watchflix-client\node_modules\next\dist\server\next-server.js:506:22)
at DevServer.run (H:\Projets\watchflix-client\node_modules\next\dist\server\dev\next-dev-server.js:456:35)
at async DevServer.handleRequest (H:\Projets\watchflix-client\node_modules\next\dist\server\base-server.js:321:20) {code: 'ERR_HTTP_HEADERS_SENT'}

But if i redirect to some other page it works fine, only when i redirect back to lobby there is problem.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!