use-pusher icon indicating copy to clipboard operation
use-pusher copied to clipboard

Reconnect after activity timeout

Open carloquilala opened this issue 5 years ago • 3 comments

Is there a way we can reconnect presence connection?

coz after some time, client stops receiving events

carloquilala avatar Dec 10 '20 05:12 carloquilala

It shouldn't do that, the whole point of websockets is that it's a long running connection. We're using it for connections that run overnight. Do you have a code sandbox you can send that I can look at?

mayteio avatar Dec 14 '20 05:12 mayteio

I currently have no sandbox but I'll try to mock the scenario... I'm using JWT to authenticate

  1. user logs in with a token that expires in an hour (token_1)
  2. 5 minutes before the token expires, token will be refreshed to extend the user session (token_2)
  3. PusherProvider still uses auth header authorization bearer (token_1) but is now invalid when trying to authenticate again (subscribing to a new channel)

what I've tried

when the system calls an api to refresh, in my saga, I put first a null token, then put next a new token

problem is it renders twice, without PusherProvider and with PusherProvider so that it can authenticate with the new token (token_2)

UPDATE

please take a look of this example codesandbox... please take a look at the request header "Authorization" property

https://codesandbox.io/s/dazzling-haibt-06kbj

carloquilala avatar Dec 16 '20 03:12 carloquilala

Hmmm, I see. The user only needs a pusher auth token once though - then the connection can stay live as long as they are active. Is the issue if, I.e. they lose wifi and reconnect, it has to get a new token because the old one might be stale?

I can’t really think of a simple way to fix this with authEndpoint. An authorizer might work better here.

mayteio avatar Feb 25 '21 03:02 mayteio