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.