From 617b291a731b7fd2512a33a19693d863e8c751eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Ka=C5=88ka?= Date: Sun, 8 Dec 2024 11:26:10 +0100 Subject: [PATCH] [Enhancement #585] Mark the current websocket security token as invalid instead of clearing it to prevent looping --- src/WebSocketApp.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/WebSocketApp.tsx b/src/WebSocketApp.tsx index 8aec98b6..f030ccc8 100644 --- a/src/WebSocketApp.tsx +++ b/src/WebSocketApp.tsx @@ -93,23 +93,28 @@ export const WebSocketWrapper: React.FC<{ loadDispatchers = true, }) => { const [securityToken, setSecurityToken] = useState(""); + const [isTokenInvalid, setIsTokenInvalid] = useState(false); useEffect(() => { const callback = () => { const token = SecurityUtils.loadToken() || ""; // using length prevents from aborting websocket due to token refresh // but will abort it when token is cleared or new one is set - if (token.length !== securityToken.length) { + if ( + token.length !== securityToken.length || + (isTokenInvalid && token !== securityToken) + ) { setSecurityToken(token); + setIsTokenInvalid(false); } }; callback(); return BrowserStorage.onTokenChange(callback); - }, [securityToken]); + }, [securityToken, isTokenInvalid]); return ( { console.error("WebSocket STOMP error", frame); - setSecurityToken(""); + setIsTokenInvalid(true); }} > {loadDispatchers && registerDispatchers()}