feat(client): add cookie-backed authentication UI
- Add session-aware login, logout and protected navigation. - Send cookie credentials for API and run-event requests with localized UI stories.
This commit is contained in:
1 parent
9e4b692444
commit
92141a25fb
26 files changed
+1191
-12
No files matched your search
@@ -5,11 +5,16 @@ import { useTranslation } from 'react-i18next';
|
||||
import { RUN_EVENTS_URL } from '../api/client';
|
||||
import type { RunEvent } from '../api/types';
|
||||
import type { NotificationToggleState } from '../ui';
|
||||
import { useAuth } from '../auth/useAuth';
|
||||
|
||||
const STORAGE_KEY = 'liqa-run-notifications';
|
||||
const RETRY_MIN_MS = 1_000;
|
||||
const RETRY_MAX_MS = 30_000;
|
||||
|
||||
export function createRunEventSource(): EventSource {
|
||||
return new EventSource(RUN_EVENTS_URL, { withCredentials: true });
|
||||
}
|
||||
|
||||
function supported(): boolean {
|
||||
return typeof window !== 'undefined' && 'Notification' in window && 'EventSource' in window;
|
||||
}
|
||||
@@ -41,6 +46,7 @@ export function useRunNotifications(): {
|
||||
state: NotificationToggleState;
|
||||
toggle: () => void;
|
||||
} | null {
|
||||
const auth = useAuth();
|
||||
const isSupported = supported();
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
@@ -81,7 +87,11 @@ export function useRunNotifications(): {
|
||||
handlers.current = { t, navigate };
|
||||
});
|
||||
|
||||
const active = isSupported && enabled && permission === 'granted';
|
||||
const active =
|
||||
isSupported &&
|
||||
enabled &&
|
||||
permission === 'granted' &&
|
||||
(!auth.enabled || auth.status === 'authenticated');
|
||||
|
||||
useEffect(() => {
|
||||
if (!active) return;
|
||||
@@ -122,7 +132,7 @@ export function useRunNotifications(): {
|
||||
};
|
||||
|
||||
const connect = () => {
|
||||
source = new EventSource(RUN_EVENTS_URL);
|
||||
source = createRunEventSource();
|
||||
source.addEventListener('open', () => {
|
||||
retryDelay = RETRY_MIN_MS;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user