using zustand for localStorage data, fixed socketio on login

This commit is contained in:
Domingo Dirutigliano
2025-07-28 16:01:41 +02:00
parent 699060ae0a
commit 97b3d97753
3 changed files with 89 additions and 11 deletions

View File

@@ -13,6 +13,7 @@ import { Firewall } from './pages/Firewall';
import { useQueryClient } from '@tanstack/react-query';
import NFProxy from './pages/NFProxy';
import ServiceDetailsNFProxy from './pages/NFProxy/ServiceDetails';
import { useAuth } from './js/store';
function App() {
@@ -22,16 +23,19 @@ function App() {
const [error, setError] = useState<string|null>()
const [loadinBtn, setLoadingBtn] = useState(false);
const queryClient = useQueryClient()
const { isAuthenticated, access_token } = useAuth()
useEffect(()=>{
socketio.auth = { token: localStorage.getItem("access_token") }
socketio.auth = { token: access_token || "" }
socketio.connect()
getStatus()
socketio.on("update", (data) => {
queryClient.invalidateQueries({ queryKey: data })
})
socketio.on("connect_error", (err) => {
errorNotify("Socket.Io connection failed! ",`Error message: [${err.message}]`)
if (access_token){
errorNotify("Socket.Io connection failed! ",`Error message: [${err.message}]`)
}
getStatus()
});
return () => {
@@ -39,7 +43,7 @@ function App() {
socketio.off("connect_error")
socketio.disconnect()
}
},[])
},[isAuthenticated])
const getStatus = () =>{
getstatus().then( res =>{