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

765
Vistas
Error de Bcrypt: se requieren datos y argumentos hash | Error [ERR_HTTP_HEADERS_SENT]: no se pueden establecer encabezados después de enviarlos al cliente

Sigo recibiendo estos 2 errores, pase lo que pase: Error: data and hash arguments required y Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

Recibo el primer error al comparar hash y texto sin formato. Recibo el segundo error en el archivo fetchUser.js cuando intento enviar el token jwt en los encabezados de solicitud

Aquí está mi ruta de inicio de sesión de userAuth:

 router.post('/login', checks.loginChecks, async (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { return res.status(400).json({ errors: errors.array() }); } const { email, password } = req.body; try { let thatOneUser = await User.find({ email }); console.log(thatOneUser); if (!thatOneUser) return res.status(403).json({ success: false, message: `Please enter the correct information!`, }); bcrypt.compare(password, thatOneUser.password, (err, result) => { if (!result) { console.log(err); return res.status(403).json({ success: false, message: `Please enter the correct information!`, err, }); } }); const authData = { id: thatOneUser.id }; const authToken = jwt.sign(authData, JWT_SECRET); res.json({ success: true, message: 'User has been logged!', authToken }); } catch (error) { res.status(500).json({ success: false, message: 'Error occured during logging the user', error, }); console.log(error); } });

y aquí está mi fetchUser.js:

 const jwt = require('jsonwebtoken'); const JWT_SECRET = 'jwtsecretabc123'; const fetchUser = (req, res, next) => { // Get the user from the jwt token and add id to req object const token = req.header('auth-token'); console.log(token); if (!token) return res.status(401).json({ success: false, message: 'Please authenticate using a valid token!', }); try { const decoded = jwt.verify(token, JWT_SECRET); req.user = decoded.user; console.log(decoded.user, ' I am decoded id!'); next(); } catch (error) { return res .status(401) .json({ success: false, message: 'failed to decode the token' }); } }; module.exports = fetchUser;

cuando hago una solicitud a localhost:5000/api/auth/login , funciona la primera vez, pero no funciona la segunda vez.

Ninguna de las otras solicitudes (registro, getUserData) tampoco funciona. ¡Cualquier ayuda será apreciada!

about 4 years ago · Juan Pablo Isaza
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