Fix issues with reconnect and logging out

Fix problems encountered logging out and in while the connection has
dropped and is in the process of reconnecting.
This commit is contained in:
Hornwitser committed 2021-03-18 23:05:59 +01:00
1 parent 6458810571
commit d627c5e094
4 files changed
+17 -10

No files matched your search

+10 -7
View File
@@ -31,6 +31,7 @@ export default function App(props) {
function clearToken() {
setToken(null);
connector.token = null;
localStorage.removeItem("master_token");
}
@@ -54,6 +55,14 @@ export default function App(props) {
connector.on("close", onClose);
connector.on("error", onError);
return () => {
connector.off("error", onError);
connector.off("close", onClose);
connector.off("connect", onConnect);
};
}, [props.control]);
useEffect(() => {
if (token && !connected) {
if (props.control.loggingOut) {
clearToken();
@@ -63,13 +72,7 @@ export default function App(props) {
connector.connect();
}
}
return () => {
connector.off("error", onError);
connector.off("close", onClose);
connector.off("connect", onConnect);
};
});
}, [token, connected]);
let page;
if (connected) {