I am currently utilizing mongoose to display admin and user information on a dashboard, but I am encountering difficulty rendering the id of a user. Below is the code I am using:
function ensureAuthenticated(req, res, next){
if(req.isAuthenticated()){
return next();
} else {
req.flash('error_msg', 'You are not logged in');
res.redirect('/dashboard/login');
}
}
/* GET Dashboard page. */
router.get('/dashboard', ensureAuthenticated, (req, res) => {
User.find({}, function(err, users) {
res.render('dashboard/index.hbs', {
pageTitle: 'Dashboard',
total: users.length,
users: users
});
});
});
<a href="/dashboard/users/{{_id}}">My profile</a>
I have added some code to the question from the repository, including the ensureAuthenticated function. Based on my observation, the model and everything else seem to be set up correctly. For example, the total renders correctly, indicating that it is receiving users data as well.