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

196
Vistas
how to break in middleware in expressjs

I have a MEAN stack based web application and I have a middle ware which validates the request for some authorization purpose. I have written the security checking part but if the user is unauthorized, the express middle ware should stop execution and return back user 401 status with a message. How can I achieve it? I tried to to use return statement in middle ware but it is not working. Though some of them works, it throws an exception and breaks the server. I want just an abrupt ending to the request. Any help will be appreciated.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Assuming that isValid is a hypothetical function to check the validity of the request.

function authMiddleware(req,res,next){
  if(isValid(req)){
   next(); // calls the next middleware
  }else {
   return res.sendStatus(401); // sends HTTP 401 back
  }
}
about 4 years ago · Santiago Trujillo 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