I try to used my local variable on EJS. It's just a varaiable to check if the user is connected. -> Like the last post on this link: How to know if user is logged in with passport.js?
So,
app.js
app.use(function (req, res, next) {
res.locals.login = req.isAuthenticated();
next();
});
view EJS
<% if (login) { %>
<div id="subMenuUser">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
</span>Menu<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right" role="menu">
<li><a href="#" role="menuitem">Menu Item 1</a></li>
<li><a href="#" role="menuitem">Menu Item 2</a></li>
<li><a href="#" role="menuitem">Menu Item 3</a></li>
</ul>
</div>
</div>
<% } %>
I get an error:
login is not defined
I would like to use this variable with all view.. possible ?
Before this method, I sent each time my variable in render like that:
res.render('ad/index', { login: req.session.user });