In order to implement manually an authentication process with websockets in NestJS, I'm using a NestJS Gateway but have troubles setting up a handler for the "upgrade" http request that is sent during the handshake before the connection of the websocket. Is there a way to set up somewhere a function that can enable me to catch this request so I can deny access asap?
This would allow to stop the process sooner and that no socket can be opened if there is no valid auth token in the http request. I found that I can validate the socket aftewards using the protocol field of a websocket instance (the client just sets a second parameter on websocket connection), but I prefer not having to deal with "bad" sockets to close just after their connection and stop them on the initial handshake through http, whatever the process.