From 6efa4e8465266f668f5010b8f1b530ff5c6acd45 Mon Sep 17 00:00:00 2001 From: Veljko Tosic Date: Tue, 10 Mar 2026 14:52:35 +0100 Subject: [PATCH] SignalR now also tries to refresh if first connection results in unauthorized response --- front/src/services/signalr.ts | 17 ++++++++++++++++- front/src/stores/auth.ts | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/front/src/services/signalr.ts b/front/src/services/signalr.ts index 0477c6b..c6b3dad 100644 --- a/front/src/services/signalr.ts +++ b/front/src/services/signalr.ts @@ -22,8 +22,23 @@ export class SignalRService { } async start(): Promise { - if (this.connection.state === HubConnectionState.Disconnected) { + if (this.connection.state !== HubConnectionState.Disconnected) return; + + try { await this.connection.start(); + } catch (err: any) { + if (err.statusCode === 401 || err.message?.includes("401")) { + const authStore = useAuthStore(); + try { + await authStore.tryRefresh(); + + await this.connection.start(); + } catch (refreshErr) { + throw refreshErr; + } + } else { + throw err; + } } } diff --git a/front/src/stores/auth.ts b/front/src/stores/auth.ts index 52042f4..e49ece3 100644 --- a/front/src/stores/auth.ts +++ b/front/src/stores/auth.ts @@ -151,6 +151,7 @@ export const useAuthStore = defineStore('auth', () => { isAuthenticated, isLoading, error, + tryRefresh, initialize, login, signup,