I have two pages, login and myservices. After a user logs in, they will be brought to myservices page, and their username should be shown.
in login.js, I have:
req.session.user = "abc";
res.redirect('/myservices');
and in myservices.js, I have:
router.get('/', function(req, res, next) {
console.error("went through get in my services");
console.error(req.session.user);
res.render('myservices', {
user: req.session.user
});
});
in my template (myservices.ejs), I try to print out user:
<%if(user){%>
<%=<p>user</p>%>
<%}%>
Whenever I login, I get redirected to myservices page and the console shows
went through get in my services
abc
but in the browser, it does not print out "abc" until I refresh the page. Why is not rendered to myservices.ejs on the first time but on the second time?
Any help is greatly appreciated!