"use client"; import { useState } from "react"; export function PasswordChangeForm() { const [currentPassword, setCurrentPassword] = useState(""); const [newPassword, setNewPassword] = useState(""); const [msg, setMsg] = useState(null); const [err, setErr] = useState(null); const [loading, setLoading] = useState(false); async function onSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setErr(null); setMsg(null); const res = await fetch("/api/portal/password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ currentPassword, newPassword }), }); const data = (await res.json().catch(() => ({}))) as { error?: string }; setLoading(false); if (!res.ok) { setErr(data.error ?? "Änderung fehlgeschlagen."); return; } setMsg("Passwort wurde aktualisiert."); setCurrentPassword(""); setNewPassword(""); } return (
{err ?

{err}

: null} {msg ?

{msg}

: null}
); }