From 0c5a681f5b2de9d12c2d6ba6921232a70831d644 Mon Sep 17 00:00:00 2001 From: Minei3oat Date: Thu, 2 Oct 2025 23:10:26 +0200 Subject: [PATCH] Reconnect to websocket on access_token change --- frontend/src/App.tsx | 6 +++--- frontend/src/js/store.ts | 15 --------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index cd8faaa..a5a56ca 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -13,7 +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'; +import { useAuthStore } from './js/store'; function App() { @@ -23,7 +23,7 @@ function App() { const [error, setError] = useState() const [loadinBtn, setLoadingBtn] = useState(false); const queryClient = useQueryClient() - const { isAuthenticated, access_token } = useAuth() + const { access_token } = useAuthStore() useEffect(()=>{ socketio.auth = { token: access_token || "" } @@ -43,7 +43,7 @@ function App() { socketio.off("connect_error") socketio.disconnect() } -},[isAuthenticated]) + },[access_token]) const getStatus = () =>{ getstatus().then( res =>{ diff --git a/frontend/src/js/store.ts b/frontend/src/js/store.ts index 13fff84..cea0bbb 100644 --- a/frontend/src/js/store.ts +++ b/frontend/src/js/store.ts @@ -42,21 +42,6 @@ export const useAuthStore = create()( ) ); -// Hook personalizzati per un uso più facile nei componenti -export const useAuth = () => { - const { access_token, setAccessToken, clearAccessToken, getAccessToken } = useAuthStore(); - - const isAuthenticated = !!access_token; - - return { - access_token, - isAuthenticated, - setAccessToken, - clearAccessToken, - getAccessToken, - }; -}; - interface SessionState { home_section: string | null; setHomeSection: (section: string | null) => void;