Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
How to catch 401 Unauthorized from SignalR after token expired

I have built an page that gets real-time data from my azure functions backend via SignalR. Lets say i stay on the page, watching the data for 1 hour, and i might get a disconnect, the signalr client will try to reconnect automatically, this works fine. But when it tries to reconnect the jwt token might have expired and a 401 is throw from the signalr client.

Is there any way to catch this 401 from the signalr client when a reconnect is fired?

Many people seems to use .onclose() but will not work for me, or fetching a new jwt token every time they connect, i guess this might be the way i need to proceed, but i prefer if it would be possible to catch it instead, that would be a better fix in my opinion.

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();

Hope you understand what I'm looking for here! Cheers!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That is why on the { accessTokenFactory: () => store.state.accessToken } you should pass a function that will refresh the token. So when the token expires, it will automatically check for new token from this method. So don't store the token in store.state.accessToken...

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!