Nodejs / Express. resume session

I have a simple nodejs / express application. To save user authentication, I use:

req.session.auth = user;

but this I found a regeneration method:

req.session.regenerate(function (err) {
   req.session.auth = user;
});

My question is: should I use the regeneration method or just req.session.auth = user;

+5
source share
1 answer

I would lean toward req.session.regenerate, but it depends on what you are trying to do. If you just do req.session.auth = user, you save auth for the session. However, if you use regenerate, you will actually clear the entire session, and then save auth.

, . , , , .

+9

All Articles