Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Rendering User ID ExpressJS

Currently using mongoose to render admin and user information on a dashboard however i can't seem to render the id of a user

Here is my code

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>

Added some code to the question from the repo. Added the ensureAuthenticated function. From what I can see the model and everything is setup correctly and as an example the total renders correctly so it a getting users.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When you debug the req that you have, something (I suspect Passport) has included a user variable directly there, so you can feed that into your view.

/* 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,
      currentUser: req.user
    });
  });
});

And in your view you can use that

<a href="/dashboard/users/{{currentUser._id}}">My profile</a>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!