node.js - How do I write a conditional for express-sessions login/logout in my main handlebars layout? -


i have login/logout routes written in controllers.

//login form app.get('/login', function (req, res) {     res.render('../views/signup-signin/login'); });  //login post app.post('/login', function (req, res) {     user.find(req.body.username, function (user) {         bcrypt.compare(req.body.password, user.password, function (err, result) {             if (result) {                 req.session.currentuser = user.id;                 res.redirect('/');             } else {                 res.redirect('/login');             }         });     }); });  //logout app.delete('/logout', function (req, res) {     req.session.currentuser = null;     res.redirect('/'); }); 

what i'm having trouble being able write if/else statement in 'main.handlebars' layout renders sign up/login when req.session.currentuser = null, , logout when req.session.currentuser = user.id

<div id="signin_up">         <a href="/signup"><button>sign up</button></a>         <a href="/login"><button>login</button></a> </div>  <form action="/logout" method="post">     <input type="hidden" name="_method" value="delete">     <input type="submit" value="logout"> </form> 

i can't figure out how access sessions id , write in script tag in 'main.handlebars' file.

can me feature working?

thanks ahead of time!


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -