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);
}
}
)
);