Fix WebSocket auth error on initial page load
Skip WebSocket connection attempt when no auth token is available. Previously, the WebSocketProvider would try to connect immediately on mount (even on login page) with an empty token, causing "Invalid token format" errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6ee80e67aa
commit
ca93d24ac5
1 changed files with 10 additions and 4 deletions
|
|
@ -35,10 +35,16 @@ export function WebSocketProvider({ children }: WebSocketProviderProps) {
|
|||
initSocket(getAccessToken);
|
||||
socketInitialized = true;
|
||||
}
|
||||
|
||||
console.log('🔧 [GPT-5 Context] Connecting socket');
|
||||
connectSocket();
|
||||
|
||||
|
||||
// Only connect if we have a valid token
|
||||
const currentToken = getAccessToken();
|
||||
if (currentToken) {
|
||||
console.log('🔧 [GPT-5 Context] Connecting socket with token');
|
||||
connectSocket();
|
||||
} else {
|
||||
console.log('🔧 [GPT-5 Context] No token available, skipping WebSocket connection');
|
||||
}
|
||||
|
||||
return () => {
|
||||
// DO NOT removeAllListeners() here; we want to preserve core listeners.
|
||||
// If you must clean up, be explicit with off(event, handlerRef).
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue