I dont understand how does nodejs link up the 'user' with the data of user model.
for example. :
router.post('/authenticate',function (req, res, next) {
const username = req.body.username,
password = req.body.password;
User.getUserByUsername(username, function (err, user) {
if(err) throw err;
if(!user){
return res.json({success: false, msg: 'User not found' })
}
User.comparePassword(password, user.password, function (err, isMatch) {
if(err) throw err;
if(!isMatch){
const token = jwt.sign(user, config.secret,{
expiresIn: 604800
});
res.json({
success: true,
token :
})
}
})
});
In this i have imported the User model into 'User' and then i have even made the getUserByUsername function in the model file. But Im confused with how does node get the data using 'user' in the callback. We havent declared 'user' anywhere only 'User' has been used.
Can Someone please explain this part ? and if you have videos or resources that can clear doubts about nodeJS' working for newbies then please share those links as well. Thank You.
via Uday Saini
No comments:
Post a Comment