diff --git a/src/components/layout/sidebar.tsx b/src/components/layout/sidebar.tsx index 9a5eeb5..82f5be0 100644 --- a/src/components/layout/sidebar.tsx +++ b/src/components/layout/sidebar.tsx @@ -132,9 +132,9 @@ export const Sidebar = ({ activeUrl = "/" }: SidebarProps) => { setLogoutOpen(true); }; - const confirmSignOut = () => { + const confirmSignOut = async () => { setLogoutOpen(false); - logout(); + await logout(); navigate('/login'); }; diff --git a/src/providers/auth-provider.tsx b/src/providers/auth-provider.tsx index 6643974..ea88821 100644 --- a/src/providers/auth-provider.tsx +++ b/src/providers/auth-provider.tsx @@ -95,15 +95,20 @@ export const AuthProvider = ({ children }: AuthProviderProps) => { setIsAuthenticated(true); }, []); - const logout = useCallback(() => { - // Notify sidecar to unlock Redis session + Ozonetel logout + const logout = useCallback(async () => { + // Notify sidecar to unlock Redis session + Ozonetel logout — await before clearing tokens const token = localStorage.getItem('helix_access_token'); if (token) { const apiUrl = import.meta.env.VITE_API_URL ?? 'http://localhost:4100'; - fetch(`${apiUrl}/auth/logout`, { - method: 'POST', - headers: { Authorization: `Bearer ${token}` }, - }).catch(() => {}); + try { + await fetch(`${apiUrl}/auth/logout`, { + method: 'POST', + headers: { Authorization: `Bearer ${token}` }, + signal: AbortSignal.timeout(5000), + }); + } catch (err) { + console.warn('Logout cleanup failed:', err); + } } setUser(DEFAULT_USER);