Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroying a handshake after logout. socket.io

Hello I am trying to build chat into an application. What I am wondering is when the user logs out of the website how do I also destroy the socket.io handshake associated with that session so the user cannot send messages from say another tab when he is logged out.

I am using expressjs if that is any help.

like image 923
powerc9000 Avatar asked Dec 26 '22 18:12

powerc9000


1 Answers

Well in case anyone ever find this and wants to know I did figure it out. You can access the sockets disconnect function. I had object of users ids and their socket id so when someone logged out I called

app.get("/logout", function(req,res){
  //do other logging out stuff
  sockets.disconnectUser(req.session.user_id);
}

// Disconnect User function
sockets.disconnectUser = function(user_id){
  sockets.socket(users[user_id]).disconnect();
}
like image 190
powerc9000 Avatar answered Dec 31 '22 08:12

powerc9000