h2oai / wave

Realtime Web Apps and Dashboards for Python and R
https://wave.h2o.ai
Apache License 2.0
3.98k stars 327 forks source link

feat: Redirect to login on WS reconnect if auth specified #2157

Closed mturoci closed 11 months ago

mturoci commented 11 months ago

This PR solves the problem when websockets is not able to reconnect due to expired session. Instead of noop, it now redirects users to a login screen to renew the session.

As per WS spec:

If the status code received from the server is not 101, the client handles the response per HTTP [RFC2616] procedures. In particular, the client might perform authentication if it receives a 401 status code; the server might redirect the client using a 3xx status code (but clients are not required to follow them), etc. Otherwise, proceed as follows.

Clients (browser in our case) are not required to follow HTTP redirects, so they do not. For that reason, redirect request is sent as payload which is then handled manually.

@geomodular would you mind having a look at the code once you have time?