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

171
Views
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
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!