Reputation: 425
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
Upvotes: 2
Views: 1283
Reputation: 14975
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) {
});
});
Upvotes: 3