SignalR now also tries to refresh if first connection results in unauthorized response
This commit is contained in:
@@ -22,8 +22,23 @@ export class SignalRService {
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
isAuthenticated,
|
||||
isLoading,
|
||||
error,
|
||||
tryRefresh,
|
||||
initialize,
|
||||
login,
|
||||
signup,
|
||||
|
||||
Reference in New Issue
Block a user