twelventiT
tRPC2y ago
11 replies
twelventi

need help refreshing websocket

We currently are using tRPC w/ react and websockets. We’re using the URL of the websocket as the auth token to the websocket

I.e.

ws://localhost?token=12345

We want to be able to kill this websocket connection and reopen one with a new token, I.e.

ws://localhost?token=12346

I’ve tried putting the trpcClient in react state, but when the state updates the old websocket connections stay open.

I’ve also tried setting the URL with a function, and manually killing the websocket, and letting the WS automatically reconnect, but there’s no way to manually kill the websocket from the client

Does anyone have advice or could like a pattern maybe where the websocket url has to dynamically change. (Or has a better way to continually authenticate a websocket connection)
Was this page helpful?