February 2019
Beginner
694 pages
18h 4m
English
Now that we have a working login module to handle a simple login request, we can redirect the browser session back to our home page, and the Index.ts request handler via the call to res.redirect('/'). Let's update our Index.ts request handler to work with the username value that we have stored in the session, as follows:
router.get('/', (req, res, next) => {
res.render('index',
{ title: 'Express'
,username : req.session!['username']
}
);
});
Here, we have simply added a new property to the object that is passed to our index.hbs template named username. The value of this property is retrieved from our session. We can now update our index.hbs view template as follows:
<h1>{{title}}</h1> <p>Welcome to {{title}}</p> ...Read now
Unlock full access