In my application i want the user to enter username and password and then username is first check in the database using find query and if username finds then it renders the new page to the user. The problem is if i enter a wrong username and password then it also renders a new page and the page is also not completely load. please tell me what is the mistke.
In app.js I have written:
app.post('/profile',users.login);
in users.js i have written:
exports.login=function(req,res){
console.log("login called");
PersonalInfo.findOne({ name:req.params.userName}, function(err,data){
if(err)
{
console.log("find is not done");
console.log(data);
}
else{
res.render("/profilearea.ejs");
}
})
}
When a findOne
query fails to find a matching document, it's not considered an error. Instead, the 'not found' case is indicated by the data
parameter to the findOne
callback being null
.
Your findOne
callback function's code should look something like this instead:
if(err || !data)
{
console.log("find is not done");
}
else{
res.render("/profilearea.ejs");
}