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

Était-ce utile?

La 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) {

  });
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top