Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda