Files
ProxmoxVE-Local/src/app/_components/AuthGuard.tsx
CanbiZ (MickLesk) 3fdf438c6d Wrap modals in portal and use zIndex
Use ModalPortal and zIndex values from useRegisterModal across modal components to avoid hardcoded z-50 stacking. Updated ExecutionModeModal, LXCSettingsModal, PublicKeyModal, ReleaseNotesModal, SetupModal, StorageSelectionModal, and TextViewer to import ModalPortal, capture the zIndex returned by useRegisterModal, wrap modal markup in <ModalPortal>, and apply style={{ zIndex }} to backdrops; LXC result overlay uses zIndex + 10 for proper stacking. Also changed LoadingOverlay in VersionDisplay to render with createPortal(document.body) and added the import. These changes centralize stacking behavior and prevent z-index conflicts when multiple modals/overlays are present.
2026-04-01 15:12:10 +02:00

46 lines
1.4 KiB
TypeScript

'use client';
import { useState, type ReactNode } from 'react';
import { useAuth } from './AuthProvider';
import { AuthModal } from './AuthModal';
import { SetupModal } from './SetupModal';
interface AuthGuardProps {
children: ReactNode;
}
export function AuthGuard({ children }: AuthGuardProps) {
const { isAuthenticated, isLoading, setupCompleted, authEnabled, refreshConfig } = useAuth();
const [localSetupCompleted, setLocalSetupCompleted] = useState(false);
const handleSetupComplete = async () => {
setLocalSetupCompleted(true);
await refreshConfig();
};
// Show loading while AuthProvider is still checking
if (isLoading || setupCompleted === null) {
return (
<div className="min-h-screen bg-background flex items-center justify-center">
<div className="text-center">
<div className="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-primary mb-4"></div>
<p className="text-muted-foreground">Loading...</p>
</div>
</div>
);
}
// Show setup modal if setup has not been completed yet
if (!setupCompleted && !localSetupCompleted) {
return <SetupModal isOpen={true} onComplete={handleSetupComplete} />;
}
// Show auth modal if auth is enabled but user is not authenticated
if (authEnabled && !isAuthenticated) {
return <AuthModal isOpen={true} />;
}
// Render children if authenticated or auth is disabled
return <>{children}</>;
}