I am trying to transmit a cookie back to the server, long after an authorization has occurred. The reason being I want to check if a user is still logged in after a socket has been open for a while. Is there a way to do this with socket.io? Maybe by forcing an authorization again; is this possible?
Share
You should be able to do that by enabling the socket.io authorization. Once enabled it will call into the provided function when socket.io connects.
Here is some code I used a while ago that should get you started.
Once you set the
dataproperties (e.g.data.useridin the above example) you can access them by via thesocket.handshakeobject. For example:On the client you would just emit the
reauthorize-userevent and listen to thereauthorization-resultevent. You could obviously have a setTimeout to perform the check in certain intervals.