SignalR now also tries to refresh if first connection results in unauthorized response

This commit is contained in:
2026-03-10 14:52:35 +01:00
parent 8fa0de6094
commit 6efa4e8465
2 changed files with 17 additions and 1 deletions

View File

@@ -22,8 +22,23 @@ export class SignalRService {
} }
async start(): Promise<void> { async start(): Promise<void> {
if (this.connection.state === HubConnectionState.Disconnected) { if (this.connection.state !== HubConnectionState.Disconnected) return;
try {
await this.connection.start(); 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;
}
} }
} }

View File

@@ -151,6 +151,7 @@ export const useAuthStore = defineStore('auth', () => {
isAuthenticated, isAuthenticated,
isLoading, isLoading,
error, error,
tryRefresh,
initialize, initialize,
login, login,
signup, signup,