'use client'; /** * Password gate — shown when accessing a protected album/subpage. * Submits to /api/auth and refreshes on success. */ import { useState } from 'react'; import styles from './PasswordGate.module.css'; import { useDictionary } from './I18nProvider'; interface PasswordGateProps { slug: string; title: string; type?: 'subpage' | 'album' | 'journal' | 'site'; } export default function PasswordGate({ slug, title, type = 'subpage' }: PasswordGateProps) { const t = useDictionary(); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(''); setLoading(true); try { const res = await fetch('/api/auth', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ slug, password, type }), }); if (res.ok) { window.location.reload(); } else { setError(t.password.incorrect); setPassword(''); } } catch { setError(t.password.failed); } finally { setLoading(false); } } return (
{type === 'site' ? t.password.siteSubtitle : t.password.subtitle}
{error && ({error}
)}