Answer the question
In order to leave comments, you need to log in
Working with sessions in express.js?
I work with the handlebars templating engine. The server has several views from one template, each time I switch to another view I get a get request, but at the same time I also need to give a session so that the page displays the username. There is no desire to transfer it every time, how can I fix this? (Store the name in cookies?).
app.get('/aboutcompany',function (req,res) {
req.session.newUser ? res.render('aboutcompany',{userName:req.session.newUser.name}) :
res.render('aboutcompany');
});
Answer the question
In order to leave comments, you need to log in
the easiest way is to pass either in cookies or through the request header. how do you determine that the user is logged in at all? If you use JWT for authorization, then you can just encode the necessary fields in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question