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

311
Views
¿Axios? Error no capturado (en promesa): la solicitud falló con el código de estado 500

Después de ejecutar el método de publicación de axios, da un error sin importar cómo vaya a la ruta '/api/user', si trato de ejecutar la función getUser después de ejecutar la función onSubmitLogin, todavía da un error.

Adjunto todos los códigos relevantes.

Método de publicación de inicio de sesión de usuario axios

 function onSubmitLogin(data) { var url = "http://localhost:3001/api/user/login"; axios({ method: "POST", data: { username:data.username, password:data.password }, withCredentials: true, url: url }).then(response => console.log(response)) }

Nodejs del método de publicación de inicio de sesión del usuario

 exports.userLogin = (req, res, next) => { passport.authenticate('local', (err, user, info) => { if (err) throw err; if (!user) { res.status(404).send('user not found') } else { req.login(user, err => { if (err) throw err; res.status(200).send(req.user) }) } })(req,res,next) }

getUser función axios

 function getUser() { var getUrl = "http://localhost:3001/api/user" axios({ method:"GET", withCredentials:true, url:getUrl, }).then(response => console.log(response.data)) }

método de obtención de usuario nodejs

 exports.getUser = (req,res) => { res.send(req.user) }

y pasaporte-config.js

 const LocalStrategy = require('passport-local').Strategy const bcrypt = require('bcrypt'); const User = require('./models/userModel.js'); function initialize(passport) { passport.use( new LocalStrategy((username, password, done) => { User.findOne({ username: username }) .then((user, err) => { if (err) throw err; if (!user) return done(null, false); bcrypt.compare(password, user.password, (err, result) => { if (err) throw err; if (result) { return done(null, user) } else { return done(null, false) } }) }) }) ); passport.serializeUser((user, cb) => { cb(null, user.id) }); passport.deserializeUser((id, cb) => { User.findOne({ _id: id }) .then((err, user) => { cb(err, user) }) }) } module.exports = initialize;

Editar

No recibo este error cuando configuro el valor de withCredentials en falso, pero en ese momento el sistema de autenticación no funciona correctamente.

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!