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:
michael 2026-01-05 12:15:04 -06:00
parent ae8d8854c7
commit 9758c0e495

View file

@ -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).