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

179
Vistas
EJS partials - if user is logged in

Help im stuck! been trying to teach myself some node for fun and decided on making a login system for a website.. thats all up and running but im stuck with some EJS...

I used the below function to check if the user is logged in that I use and works fine when rendering views but I wondered is there any way to use this function to render a partial EJS?

Ideally I want the partial ejs file to check if user logged in output this otherwise output something else in html?

//Used to protect any route that needs to be protected by a login.
module.exports = {
    ensureAuthenticated: function(req, res, next) {
        if(req.isAuthenticated()){
            return next();
        }
        req.flash('error_msg', 'Please log in to continue');
        res.redirect('/users/login');

    }
}

Basically in a partial EJS I want different navigation based on whether the user is logged in or out? is this possible?

<% if (ensureAuthenticated) { %>
Logged in
<%} else { %>
Logged out
<% } %>

Thankyou in advance for any advice and apologies if missing anything.

about 4 years ago · Juan Pablo Isaza
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