"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { getCurrentUserId } from "@/actions/admin/password"; export default function ChangePasswordPage() { const router = useRouter(); const [password, setPassword] = useState(""); const [confirm, setConfirm] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(null); if (password.length < 8) { setError("Password must be at least 8 characters."); return; } if (password !== confirm) { setError("Passwords do not match."); return; } setLoading(true); try { const res = await fetch("/api/auth/change-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ password }), }); const data = await res.json(); if (!res.ok || data.error) { setError(data.message ?? data.error ?? "Failed to update password."); setLoading(false); return; } router.push("/admin"); router.refresh(); } catch { setError("An unexpected error occurred. Please try again."); setLoading(false); } } return (

Change Password

You must set a new password before continuing.

{error && (
{error}
)}
setPassword(e.target.value)} required minLength={8} className="w-full rounded-xl border border-zinc-700 bg-zinc-800 px-4 py-3 text-zinc-100 placeholder:text-zinc-600 outline-none focus:border-violet-500 transition-colors" placeholder="Min. 8 characters" autoFocus />
setConfirm(e.target.value)} required className="w-full rounded-xl border border-zinc-700 bg-zinc-800 px-4 py-3 text-zinc-100 placeholder:text-zinc-600 outline-none focus:border-violet-500 transition-colors" placeholder="Repeat password" />
Sign out instead
); }