"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { Icon } from "@/components/icons"; import { PasswordInput } from "@/components/password-input"; import { Button, Card, CardTitle, Field, Notice } from "@/components/ui"; import { ApiError, apiJson } from "@/lib/api-client"; export function ChangePasswordForm({ minLength }: { minLength: number }) { const [current, setCurrent] = useState(""); const [next, setNext] = useState(""); const [repeat, setRepeat] = useState(""); const [pending, setPending] = useState(false); const [error, setError] = useState(null); const [done, setDone] = useState(false); const mismatch = repeat.length > 0 && next !== repeat; const tooShort = next.length > 0 && next.length < minLength; const submit = async () => { setPending(true); setError(null); setDone(false); try { await apiJson("/api/auth", { method: "POST", json: { action: "change-password", currentPassword: current, newPassword: next, }, }); setCurrent(""); setNext(""); setRepeat(""); setDone(true); } catch (caught) { setError( caught instanceof ApiError ? caught.message : "Das Passwort konnte nicht geändert werden.", ); } finally { setPending(false); } }; return ( Passwort ändern
{ event.preventDefault(); if (mismatch || tooShort) return; void submit(); }} > {error ? {error} : null} {done ? ( Das Passwort wurde geändert. Andere Geräte wurden abgemeldet. ) : null} setCurrent(event.target.value)} /> setNext(event.target.value)} /> setRepeat(event.target.value)} />
); } export function SignOutCard() { const router = useRouter(); const [pending, setPending] = useState(false); return ( Abmelden
); }