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

771
Views
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
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!