diff --git a/src/components/TelegramConnectionModal.tsx b/src/components/TelegramConnectionModal.tsx index 5d55c541c..f3e0d1cec 100644 --- a/src/components/TelegramConnectionModal.tsx +++ b/src/components/TelegramConnectionModal.tsx @@ -155,6 +155,7 @@ const TelegramConnectionModal = ({ }, async (err) => { // Handle errors + console.error("[mtproto] signInWithQrCode error:", err); const errorMessage = err.message || "Authentication error"; // Check if it's a 2FA password needed error @@ -208,6 +209,7 @@ const TelegramConnectionModal = ({ onComplete(); onClose(); } catch (err) { + console.error("[mtproto] Telegram login flow failed:", err); setIsAuthenticating(false); const errorMessage = err instanceof Error ? err.message : "Authentication failed"; diff --git a/src/providers/TelegramProvider.tsx b/src/providers/TelegramProvider.tsx index dda70d489..bbd3ca31c 100644 --- a/src/providers/TelegramProvider.tsx +++ b/src/providers/TelegramProvider.tsx @@ -131,7 +131,7 @@ const TelegramProvider = ({ children }: TelegramProviderProps) => { userId, ]); - // Check connection status periodically to keep user online + // Check connection status once when Telegram reports as connected useEffect(() => { if ( !shouldSetupTelegram || @@ -151,9 +151,6 @@ const TelegramProvider = ({ children }: TelegramProviderProps) => { }; checkConnection(); - const interval = setInterval(checkConnection, 20000); - - return () => clearInterval(interval); }, [shouldSetupTelegram, isInitialized, connectionStatus, userId]); const checkConnection = async (): Promise => { diff --git a/src/services/socketService.ts b/src/services/socketService.ts index 22b861ffc..cb86deb6e 100644 --- a/src/services/socketService.ts +++ b/src/services/socketService.ts @@ -19,14 +19,10 @@ class SocketService { * Connect to the socket server with authentication */ connect(token: string): void { - if (!token) { - return; - } + if (!token) return; // Don't connect if already connected with the same token - if (this.socket?.connected && this.token === token) { - return; - } + if (this.socket?.connected && this.token === token) return; // Disconnect existing connection if token changed or socket exists if (this.socket) { @@ -66,7 +62,7 @@ class SocketService { reconnectionDelay: 1000, reconnectionAttempts: 5, forceNew: true, // Force new connection to ensure auth is sent - timeout: 20000, // Increase timeout for initial connection + timeout: 2000, // Increase timeout for initial connection upgrade: true, // Allow upgrade from polling to websocket query: {}, // Explicitly prevent token from being added to query string }; @@ -77,6 +73,7 @@ class SocketService { this.socket.on("connect", () => { const socketId = this.socket?.id || null; const uid = getSocketUserId(); + console.log("connected", socketId, uid); store.dispatch(setStatusForUser({ userId: uid, status: "connected" })); store.dispatch(setSocketIdForUser({ userId: uid, socketId })); });