U
U
UNy2018-07-16 22:30:13
Node.js
UNy, 2018-07-16 22:30:13

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

1 answer(s)
A
Aleksei Podgaev, 2018-08-01
@UNy

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 question

Ask a Question

731 491 924 answers to any question