'use client' import { useAuth } from '@nextsparkjs/core/hooks/useAuth' import { useRouter } from 'next/navigation' import { useEffect, Suspense } from 'react' import { Loader2 } from 'lucide-react' import { DashboardProviders } from '@nextsparkjs/core/providers/DashboardProviders' import { DashboardTranslationPreloader } from '@nextsparkjs/core/lib/i18n/DashboardTranslationPreloader' import { TranslationDebugger } from '@nextsparkjs/core/utils/dev/TranslationDebugger' import { useEnsureUserMetadata } from '@nextsparkjs/core/hooks/useEnsureUserMetadata' import { useAuthMethodDetector } from '@nextsparkjs/core/hooks/useAuthMethodDetector' /** * Auth Method Detector Wrapper (uses useSearchParams internally) */ function AuthMethodDetectorWrapper() { useAuthMethodDetector() return null } /** * Dashboard Layout Content */ function DashboardLayoutContent({ children }: { children: React.ReactNode }) { const { user, isLoading } = useAuth() const router = useRouter() // Asegurar que el usuario tenga metadata default useEnsureUserMetadata() useEffect(() => { if (!isLoading && !user) { router.push('/login') } }, [user, isLoading, router]) if (isLoading) { return (
) } if (!user) { return null } return ( <> {/* Precargar traducciones del dashboard para mejorar UX de navegación */} {/* Debugger de traducciones (solo en desarrollo con ?debug-i18n=true) */} {/* Detect and save auth method from OAuth redirects (wrapped in Suspense) */} {/* Children run within authenticated boundary - nested layouts CAN be themed but security is guaranteed */}
{children}
) } /** * CORE SECURITY LAYOUT - NOT OVERRIDEABLE BY THEMES * * This layout provides essential authentication and security measures * that cannot be bypassed by theme overrides. All dashboard routes * run within this authenticated boundary. * * SECURITY: This layout is intentionally NOT using template resolver * to prevent themes from bypassing authentication. */ export default function CoreDashboardLayout({ children }: { children: React.ReactNode }) { return ( {children} ) }