-1

I am a rookie in nodejs. I am making an e-commerce site using kraken framework and dust template. I want to display Log in and Log out text depending upon the session status. My logout and login functionality is working fine. I want to hide the log-in text when the user has logged in and the logout text when the user has logged out.How can I achieve that? My middleware for checking if a user has logged in is as follows :

app.get('*', function(req, res, next) {
    res.locals.user = req.user || null;
    next();
  });

How can I achieve that using dust-helpers?

kinny94
  • 376
  • 1
  • 5
  • 22

1 Answers1

1

At some point, you'll be calling res.render() with a template and a context object to render.

First, you need to pass your user object as part of the context:

return res.render(myTemplate, {
  ...
  user: res.locals.user,
  ...
});

Then, in the template, you can see if user exists:

{?user}
  Logout link
{:else}
  Login link
{/user}
Interrobang
  • 16,984
  • 3
  • 55
  • 63