I'm new in development and I try to make an authorisation in my test site. Everything is okay in server's part, I can create a user and then login to it, but when I want to display information of the user, my program nothing, but also this message: "Handlebars: Access has been denied to resolve the property "username" because it is not an "own property" of its parent."
Please, tell me, what am I doing wrong?
Login function:
async login(req, res){
try {
const {username, password} = req.body;
const user = await User.findOne({username: username});
if(!user){
return res.status(400).json({message: ''});
}
const validPassword = bcrypt.compareSync(password, user.password);
if(!validPassword){
return res.status(400).json({message: ''});
}
const token = generateAccessToken(user._id, user.roles);
res.render('myPage',{
title: 'list',
user
});
} catch(e) {
console.log(e);
res.status(400).json({message: 'Server Error'});
}
}
HTML:
<div class="container">
{{#if user}}
<p> {{this.user.username}} </p>
{{else}}
<p>Error</p>
{{/if}}
</div>