Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda