// Copyright: (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) import { useMemo } from 'react'; import { AccessGuard } from '@archer/domain'; import { useAuthenticatedUser } from '@/features/auth/hooks/useAuthenticatedUser'; import { toAuthOrigin, toEmployeeRole } from '@/presentation/lib/enumGuards'; /** * Hook that creates an AccessGuard from the current AuthenticatedUser. Reactive * — reruns when the store patches authOrigin / role after a refresh. */ export function useAccessGuard(): AccessGuard { const user = useAuthenticatedUser(); return useMemo( () => new AccessGuard({ authOrigin: toAuthOrigin(user?.authOrigin), role: toEmployeeRole(user?.role), }), [user?.authOrigin, user?.role], ); }