react-use-websocket
react-use-websocket copied to clipboard
Set cookies to the websocket URL
How to set / attach cookies to the web socket connection URL? We are connecting to mattermost server for websocket connection. We need to set/attach some cookies for this connection to receive messages. How we set cookies in the headers?

I'm not an expert in this so take this advice with caution. When using the Cloudflare Zero Trust proxy, I have the websocket client first establishes an HTTP/HTTPS connection with the websocket server to setup authentication cookies etc . Then requests from the browser to the websocket will include cookies. Currently I'm doing this with a redirect e.g. user connects to https://site.com and the client javascript checks the URL and redirects to the websocket server's url e.g. https://socket.site.com/authenticate which redirects back to https://site.com/authenticated (in Cloudflare Zero Trust I'm sharing the authentication for both domains and the user will have to login to get access to https://site.com to start with)
Is there any solution for this issue?