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

268
Vistas
React.js Axios 400 (Bad Request) to backend node.js passport.js

The problem is that when i make post request via postman localhost:3005/api/users/signup it creates user in database and everything works. but when i try to post from front-end using Axios it shows 400 bad request

Here is my front end code to how i'm calling post request. addUser has the same structure of what im posting via postman.

postUser: async (addUser) => {
    await axios.post(`${APIURLusers}signup/`, {addUser});
},

If POST via postman works i think the error is on the react side but here is backend code router.js

router.post(
'/signup',
passport.authenticate('signup', { session: false }),
async (req, res, next) => {
  res.json({
    message: 'Signup successful',
    user: req.user
  });
});

and auth.js

passport.use(
'signup',
new localStrategy(
  {
    usernameField: 'email',
    passwordField: 'password',
    passReqToCallback: true
  },
  async (req,email, password, done) => {
    try {
        const data = new UserModel({
            firstName: req.body.firstName,
            lastName: req.body.lastName,
            phone: req.body.phone,
            email: email,
            password: password
        });

        data.save();
      return done(null, data);
    } catch (error) {
        console.log(error);
      done(error);
    }
  }
)

);

about 4 years ago · Santiago Gelvez
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