'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { Lock } from 'lucide-react'; import { apiFetch } from '@/lib/browser-navigation'; export default function ChangePasswordPage() { const router = useRouter(); const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(''); setSuccess(false); if (newPassword.length < 8) { setError('New password must be at least 8 characters.'); return; } if (newPassword !== confirmPassword) { setError('New passwords do not match.'); return; } setLoading(true); const res = await apiFetch('/api/admin/change-password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ currentPassword, newPassword }), }); if (res.ok) { setSuccess(true); setCurrentPassword(''); setNewPassword(''); setConfirmPassword(''); setTimeout(() => router.push('/admin'), 2000); } else { const data = await res.json().catch(() => ({})); setError(data.error || 'Failed to change password.'); } setLoading(false); } return (

Change Password

Update your admin password.

setCurrentPassword(e.target.value)} required className="w-full h-9 pl-9 pr-3 rounded-md border border-input bg-background text-sm text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" autoComplete="current-password" />
setNewPassword(e.target.value)} required minLength={8} className="w-full h-9 px-3 rounded-md border border-input bg-background text-sm text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" autoComplete="new-password" />
setConfirmPassword(e.target.value)} required minLength={8} className="w-full h-9 px-3 rounded-md border border-input bg-background text-sm text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" autoComplete="new-password" />
{error && (

{error}

)} {success && (

Password changed. Redirecting...

)}
); }