Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda