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

88
Views
La respuesta del método POST no hace nada. no puedo res.json() ni res.render()
const bcrypt = require('bcryptjs'); const jwt = require('jsonwebtoken'); const JWT_SECRET = require('../../config/keys').JWT_SECRET; const userModel = require('../../models/User'); const postChangePassword = async (req, res) => { let isChanged = true; const { token, newPassword } = req.body; try { const verified = jwt.verify(token, JWT_SECRET); const _id = verified.id; const hashedPassword = await bcrypt.hash(newPassword, 8); await userModel.updateOne({ _id }, { $set: { password: hashedPassword } }); } catch (error) { isChanged = false; console.log(error); } res.render('change-password', { isChanged }); console.log('wow'); }; module.exports = postChangePassword;

Mi controlador es así para usar app.post("/change-password", postChangePassword) . Pero res render no responde. No da error, pero no funciona, incluso si intento res.json o redirigir. La solicitud proviene de otro método fetch() en la aplicación y los otros códigos funcionan bien, excepto res.something.

Y aquí está mi código POST de donde proviene la solicitud

 <script> async function postToken(event) { event.preventDefault(); const password = document.getElementById('password').value const token = localStorage.getItem('token') const result = await fetch('/authUser/change-password', { method: 'POST', mode: 'cors', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ newPassword: password, token: token }), }) } const form = document.getElementById('form') form.addEventListener('submit', postToken) </script>
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!