From 1ea2eda04a8a265c05bf13c978f3b0883ac7bda2 Mon Sep 17 00:00:00 2001 From: Ivan Vasilev Date: Thu, 29 Oct 2026 23:49:49 +0300 Subject: [PATCH] Keep the session on network errors when restoring it Only a 401 clears the saved token; a network error or 5xx while the panel restarts retries every 5 s instead of dropping to the login screen. --- awg-ui/src/App.tsx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/awg-ui/src/App.tsx b/awg-ui/src/App.tsx index 645be6e..6e7bb61 100644 --- a/awg-ui/src/App.tsx +++ b/awg-ui/src/App.tsx @@ -174,13 +174,25 @@ export default function App() { // Восстановить сессию из сохранённого токена useEffect(() => { + // Сбрасываем сессию только на 401: сетевой сбой или 502, пока панель перезапускается, + // раньше тоже выкидывали на экран входа. В остальных случаях пробуем снова через 5 с. const saved = localStorage.getItem(TOKEN_KEY); - if (saved) { - startSession(saved).catch(() => { - localStorage.removeItem(TOKEN_KEY); - setToken(''); + if (!saved) return; + let timer: ReturnType | undefined; + let alive = true; + const attempt = () => { + startSession(saved).catch(e => { + if (!alive) return; + if (axios.isAxiosError(e) && e.response?.status === 401) { + localStorage.removeItem(TOKEN_KEY); + setToken(''); + } else { + timer = setTimeout(attempt, 5000); + } }); - } + }; + attempt(); + return () => { alive = false; clearTimeout(timer); }; }, [startSession]); // Состояние серверов (онлайн, пиры) обновляем раз в 15 с, пока открыта панель.