diff --git a/src/WebSocketApp.tsx b/src/WebSocketApp.tsx index dc0f035a..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(); + 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.warn("Unhandled STOMP receipt", receipt) } + onStompError={(frame) => { + console.error("WebSocket STOMP error", frame); + setIsTokenInvalid(true); + }} > {loadDispatchers && registerDispatchers()} {children}