DEV Community

Discussion on: Using WebSockets with React.js, the right way (no library needed)

Collapse
 
itays123 profile image
Itay Schechner

I suggest this solution:

  • attach the token to the Websocket URL in the query params. I.e: ws://localhost:4000/ws?token=...
  • In the server, in the connection established event, get the sessions URL (I supposed you have access to it although I can't recall), and get the search params from it.
  • validate the token, and if not validated - manually disconnect the websocket from the server.