Вопрос

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