Question

How to destroy the session of a particular user using his/her user_id ?

I have an events like when admin assign role to a normal user then, if the normal user is logged in, I have to destroy the session of the normal user.

Any help would be appreciated.

Thanks

Was it helpful?

Solution

The session of the logged in user has an id that you can save after successful login: req.session.id. Then you can retrieve that user's session from the memory store at any time and destroy it using:

sessionStore = express.session.MemoryStore();
sessionStore.get(id, function(err, sess) {
  sess.destroy (function (err) {

  });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top