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

有帮助吗?

解决方案

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

  });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top