'use client'; /** * Password gate — shown when accessing a protected album/subpage. * Submits to /api/auth and refreshes on success. */ import { useState } from 'react'; interface PasswordGateProps { slug: string; title: string; } export default function PasswordGate({ slug, title }: PasswordGateProps) { 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 }), }); if (res.ok) { window.location.reload(); } else { setError('Wrong password'); setPassword(''); } } catch { setError('Something went wrong'); } finally { setLoading(false); } } return (
This gallery is password-protected.
{error &&{error}
}