'use client'; import { useEffect, useState } from 'react'; import { useRouter } from 'next/navigation'; import { LogOut, Mail } from 'lucide-react'; import Navbar from '@/components/Navbar'; import Footer from '@/components/Footer'; import { logoUrl } from '@/lib/assets'; import { useLanguage } from '@/lib/language-context'; import { getTranslation } from '@/lib/translations'; export default function AccountPage() { const router = useRouter(); const { language } = useLanguage(); const t = getTranslation(language); const [email, setEmail] = useState(null); const [name, setName] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const loadSession = async () => { try { const response = await fetch('/api/auth/customer/session', { cache: 'no-store' }); const data = (await response.json()) as { authenticated: boolean; email: string | null; name: string | null; }; if (!data.authenticated || !data.email) { router.replace('/login?tab=customer'); return; } setEmail(data.email); setName(data.name); window.dispatchEvent(new Event('shahi-customer-auth-changed')); } catch { router.replace('/login?tab=customer'); } finally { setLoading(false); } }; void loadSession(); }, [router]); const handleLogout = async () => { await fetch('/api/auth/customer/logout', { method: 'POST' }); window.dispatchEvent(new Event('shahi-customer-auth-changed')); router.replace('/login?tab=customer'); }; if (loading) { return (
{t.auth.customer.loading}
); } return (
Shahi Kitchen

{t.auth.customer.badge}

{t.auth.customer.welcomeTitle}

{t.auth.customer.welcomeSubtitle}

{t.auth.customer.loggedInAs}

{name && (

{name}

)}
{email}
); }