Skip to content

Commit 676e1dc

Browse files
authored
Merge pull request #30 from Minei3oat/socketio
Reconnect to websocket on access_token change
2 parents c726855 + 0c5a681 commit 676e1dc

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

frontend/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Firewall } from './pages/Firewall';
1313
import { useQueryClient } from '@tanstack/react-query';
1414
import NFProxy from './pages/NFProxy';
1515
import ServiceDetailsNFProxy from './pages/NFProxy/ServiceDetails';
16-
import { useAuth } from './js/store';
16+
import { useAuthStore } from './js/store';
1717

1818
function App() {
1919

@@ -23,7 +23,7 @@ function App() {
2323
const [error, setError] = useState<string|null>()
2424
const [loadinBtn, setLoadingBtn] = useState(false);
2525
const queryClient = useQueryClient()
26-
const { isAuthenticated, access_token } = useAuth()
26+
const { access_token } = useAuthStore()
2727

2828
useEffect(()=>{
2929
socketio.auth = { token: access_token || "" }
@@ -43,7 +43,7 @@ function App() {
4343
socketio.off("connect_error")
4444
socketio.disconnect()
4545
}
46-
},[isAuthenticated])
46+
},[access_token])
4747

4848
const getStatus = () =>{
4949
getstatus().then( res =>{

frontend/src/js/store.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,6 @@ export const useAuthStore = create<AuthState>()(
4242
)
4343
);
4444

45-
// Hook personalizzati per un uso più facile nei componenti
46-
export const useAuth = () => {
47-
const { access_token, setAccessToken, clearAccessToken, getAccessToken } = useAuthStore();
48-
49-
const isAuthenticated = !!access_token;
50-
51-
return {
52-
access_token,
53-
isAuthenticated,
54-
setAccessToken,
55-
clearAccessToken,
56-
getAccessToken,
57-
};
58-
};
59-
6045
interface SessionState {
6146
home_section: string | null;
6247
setHomeSection: (section: string | null) => void;

0 commit comments

Comments
 (0)