'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'; interface PasswordGateProps { slug: string; title: string; type?: 'subpage' | 'album' | 'journal'; } export default function PasswordGate({ slug, title, type = 'subpage' }: 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, type }), }); if (res.ok) { window.location.reload(); } else { setError('Incorrect password. Please try again.'); setPassword(''); } } catch { setError('Unable to verify password. Please try again later.'); } finally { setLoading(false); } } return (
This gallery is password-protected.
{error && ({error}
)}