'use client'; import { useEffect, useState } from 'react'; import { useRouter, usePathname } from 'next/navigation'; export default function PasswordLockGuard({ children }: { children: React.ReactNode }) { const router = useRouter(); const pathname = usePathname(); const [isChecking, setIsChecking] = useState(true); const [isLocked, setIsLocked] = useState(false); useEffect(() => { // Skip check for admin and lock pages if (pathname.startsWith('/admin') || pathname === '/lock') { setIsChecking(false); return; } const checkPasswordLock = async () => { try { const response = await fetch('/api/settings'); const data = await response.json(); if (data.success && data.settings.passwordLockEnabled) { setIsLocked(true); // Redirect to lock page router.push('/lock'); } else { setIsChecking(false); } } catch (error) { console.error('Error checking password lock:', error); // On error, allow access to prevent site lockout setIsChecking(false); } }; checkPasswordLock(); }, [pathname, router]); // Show loading or nothing while checking if (isChecking) { return (
Loading...