Fix WebSocket connection in platform mode

- Skip localStorage token check when VITE_IS_PLATFORM=true
- Connect to WebSocket without token parameter in platform mode
- Allows proxy-based authentication through Cloudflare edge
This commit is contained in:
simos
2025-11-11 17:06:30 +01:00
parent 69b7b59f00
commit 0f4b3666fc

View File

@@ -21,20 +21,25 @@ export function useWebSocket() {
const connect = async () => { const connect = async () => {
try { try {
// Get authentication token // Get authentication token (skip in platform mode)
const token = localStorage.getItem('auth-token'); let token = null;
if (!token) { const isPlatform = import.meta.env.VITE_IS_PLATFORM === 'true';
console.warn('No authentication token found for WebSocket connection');
return; if (!isPlatform) {
token = localStorage.getItem('auth-token');
if (!token) {
console.warn('No authentication token found for WebSocket connection');
return;
}
} }
// Fetch server configuration to get the correct WebSocket URL // Fetch server configuration to get the correct WebSocket URL
let wsBaseUrl; let wsBaseUrl;
try { try {
const configResponse = await fetch('/api/config', { const configResponse = await fetch('/api/config', {
headers: { headers: token ? {
'Authorization': `Bearer ${token}` 'Authorization': `Bearer ${token}`
} } : {}
}); });
const config = await configResponse.json(); const config = await configResponse.json();
wsBaseUrl = config.wsUrl; wsBaseUrl = config.wsUrl;
@@ -53,9 +58,12 @@ export function useWebSocket() {
const apiPort = window.location.port === '3001' ? '3002' : window.location.port; const apiPort = window.location.port === '3001' ? '3002' : window.location.port;
wsBaseUrl = `${protocol}//${window.location.hostname}:${apiPort}`; wsBaseUrl = `${protocol}//${window.location.hostname}:${apiPort}`;
} }
// Include token in WebSocket URL as query parameter // Include token in WebSocket URL as query parameter (only in OSS mode)
const wsUrl = `${wsBaseUrl}/ws?token=${encodeURIComponent(token)}`; let wsUrl = `${wsBaseUrl}/ws`;
if (token) {
wsUrl += `?token=${encodeURIComponent(token)}`;
}
const websocket = new WebSocket(wsUrl); const websocket = new WebSocket(wsUrl);
websocket.onopen = () => { websocket.onopen = () => {