I have created a dynamic page that continuously fetches real-time information from my Azure functions backend using SignalR. If I am on the page for an hour and experience a disconnect, the signalr client will attempt to reconnect automatically, which usually works well. However, there is a possibility that the JWT token may expire during this reconnection process, resulting in a 401 error being thrown from the signalr client.
Is there a way to capture this 401 error from the signalr client when a reconnect is triggered?
Many users tend to use .onclose() or obtain a new JWT token every time they connect, which could be a potential solution. But I am wondering if there is a way to handle this scenario more effectively without necessarily fetching a new token each time. Any insights would be highly appreciated!
var connection = new signalR.HubConnectionBuilder()
.configureLogging(signalR.LogLevel.Information)
.withUrl(config.default.hostname + "/api/v1/core/signalr",
{ accessTokenFactory: () => store.state.accessToken })
.withAutomaticReconnect([0, 0, 10000])
.build();
connection.start();
I hope my query is clear! Thank you!