Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
Nodejs redirect from POST method not working

I have a logout button, which sends a POST request. After that it should redirect the user to the main page, but nothing happens. I also tried to set the status code to 302, 303...

Code:

//on click this is executed
function logout() {
  fetch('/logout', { method: 'POST' });
}
//this is called on POST request
const logout = (_req, res) => {
  res.clearCookie('token');
  res.locals.payload = undefined;
  res.redirect('/');                    //problem
};
//logged requests
POST /logout 302 23 - 0.865 ms
GET / 304 - - 6.058 ms
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If your /logout endpoint accepts GET requests, try redirecting the user there instead. For example:

function logout() {
    document.location = '/logout';
}

Otherwise, add a redirect in JavaScript once the cookies are cleared:

async function logout() {
  await fetch('/logout', { method: 'POST' });
  document.location = '/';
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda