fix(frontend): Fix SignalR 401 authentication error with dynamic token factory
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 <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,8 @@ export class SignalRConnectionManager {
|
|||||||
|
|
||||||
this.connection = new signalR.HubConnectionBuilder()
|
this.connection = new signalR.HubConnectionBuilder()
|
||||||
.withUrl(this.hubUrl, {
|
.withUrl(this.hubUrl, {
|
||||||
accessTokenFactory: () => token,
|
// Use dynamic token factory to always get the latest token
|
||||||
|
accessTokenFactory: () => tokenManager.getAccessToken() || '',
|
||||||
// 备用方案:使用 query string(WebSocket 升级需要)
|
// 备用方案:使用 query string(WebSocket 升级需要)
|
||||||
// transport: signalR.HttpTransportType.WebSockets,
|
// transport: signalR.HttpTransportType.WebSockets,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user