'use client'; import { useState, useEffect } from 'react'; interface AuthGateProps { children: React.ReactNode; } const SESSION_KEY = 'auth_session'; export default function AuthGate({ children }: AuthGateProps) { const [isAuthenticated, setIsAuthenticated] = useState(false); const [isChecking, setIsChecking] = useState(true); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); // Check for existing session on mount useEffect(() => { const session = sessionStorage.getItem(SESSION_KEY); if (session === 'authenticated') { setIsAuthenticated(true); } setIsChecking(false); }, []); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(''); setIsSubmitting(true); try { const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ''; const response = await fetch(`${basePath}/api/auth`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }) }); const data = await response.json(); if (response.ok && data.authenticated) { sessionStorage.setItem(SESSION_KEY, 'authenticated'); setIsAuthenticated(true); setPassword(''); } else { setError('Invalid password'); } } catch (err) { setError('Authentication failed'); } finally { setIsSubmitting(false); } } if (isChecking) { return (