I have built a JavaScript Server Authentication API, but am facing some issues. When I pushed this POST request using Postman:
http://localhost:3000/signup?firstName=my&secondName=Name&[email protected]&password=password
The router triggers this function:
app.post("/signup", Auth.userExist, function (req, res, next) {
if (!req.body.email || !req.body.password) {
res.json({success: false, msg: 'Please pass email and password.'});
} else {
var newUser = new User({
firstName: req.body.firstName,
lasttName: req.body.lastName,
email: req.body.email,
password: req.body.password
});
// save the user
newUser.save(function(err) {
if (err) {
return res.json({success: false, msg: 'Username already exists.'});
}
res.json({success: true, msg: 'Successful created new user.'});
});
}
});
The please pass email and password error is firing, I can't see why this would be happening?
console.log(req)and examine what's in there? This is elementary debugging. Also, are you running middleware that processes the query string? node.js does not parse the query string automatically without the appropriate middleware to do it. - jfriend00if {!req.query){? If so, that sill produces the same outcome - George Edwards