I'm going to try to authenticate a connection on socket.io.
Currently, the user is first authenticated via a REST API, then, I send the user a JsonWebToken with the authenticated user's username. After I open the connection between the client and the server, my plan is to temporarily delete that socket from the list of connected sockets to prevent the receiving and sending of data between the server while I carry out the auth.
In this auth, I verify the token and if the token is valid I re-add the socket's id to the list of connected sockets. The only problem is that the first part doesn't work. I can't seem to delete the socket from the list.
To test this I did the following.
io.on('connection', function(socket){
//temp delete socket
delete io.sockets.connected[socket.id];
console.log(io.sockets.connected);
socket.emit("test");
});
As you can see I delete the socket and emit a test event to see if the socket is still open. The message was received by the client when it shouldn't be.
Does anyone know why this occurs?
io.sockets.connecteddoes not disconnect the socket. - jfriend00