'use client'; import { useEffect } from 'react'; import { usePathname } from 'next/navigation'; // Listens for the `auth:unauthorized` event dispatched by the axios interceptor // (see services/httpClient/httpClient.ts) and bounces the user to /login. export function AuthEventListener() { const pathname = usePathname(); useEffect(() => { const locale = pathname.split('/')[1] || 'az'; const handler = async () => { await fetch('/api/clear-session', { method: 'POST' }).catch(() => {}); window.location.href = `/${locale}/login`; }; window.addEventListener('auth:unauthorized', handler); return () => window.removeEventListener('auth:unauthorized', handler); }, [pathname]); return null; }