From 048e7e7e6d34aea85e99c6e1de714fedb7191045 Mon Sep 17 00:00:00 2001 From: Yaojia Wang Date: Wed, 5 Nov 2025 20:45:51 +0100 Subject: [PATCH] fix(frontend): Fix SignalR 401 authentication error with dynamic token factory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed SignalR connection failing with 401 Unauthorized error by using a dynamic token factory instead of a static token value. Changes: - Updated accessTokenFactory to call tokenManager.getAccessToken() dynamically - This ensures SignalR always uses the latest valid JWT token - Fixes token expiration and refresh issues during connection lifecycle Issue: SignalR negotiation was failing because it used a stale token captured at connection creation time, instead of fetching the current token from localStorage on each request. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/signalr/ConnectionManager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/signalr/ConnectionManager.ts b/lib/signalr/ConnectionManager.ts index ecc62cb..5643c4d 100644 --- a/lib/signalr/ConnectionManager.ts +++ b/lib/signalr/ConnectionManager.ts @@ -36,7 +36,8 @@ export class SignalRConnectionManager { this.connection = new signalR.HubConnectionBuilder() .withUrl(this.hubUrl, { - accessTokenFactory: () => token, + // Use dynamic token factory to always get the latest token + accessTokenFactory: () => tokenManager.getAccessToken() || '', // 备用方案:使用 query string(WebSocket 升级需要) // transport: signalR.HttpTransportType.WebSockets, })