Hellow campers, kindly help me here, where am i going wrong, i am using postman to process my post request but it displays the the error please all add the fields and my fileds are all added and if i remove the statement it process an empty data to my mongo DB
app.post("/register",(req,res)=>{
const {email, password} = req.body;
if(!email && !password){
return res.status(422).json({message: "please add all the fields"})
}
const newUser = new User({
email,
password
});
newUser.save((err)=>{
if(err){
console.log(err)
}else{
res.status(200).json({message: "added to the DB"})
}
});
});
my user schema and model
const userSchema = {
email: String,
password: String
};
//Creating user model
const User = mongoose.model("User", userSchema);