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,