import React, { useState } from "react"; import { apiFetch } from "../api"; import { useAuth } from "../state"; export function UserSettingsPage() { const { tokens, refresh } = useAuth(); const [form, setForm] = useState({ current_password: "", new_password: "", confirm_password: "", }); const [message, setMessage] = useState(""); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); const submit = async (e) => { e.preventDefault(); setMessage(""); setError(""); if (form.new_password.length < 8) { setError("New password must be at least 8 characters."); return; } if (form.new_password !== form.confirm_password) { setError("Password confirmation does not match."); return; } try { setBusy(true); await apiFetch( "/me/password", { method: "POST", body: JSON.stringify({ current_password: form.current_password, new_password: form.new_password, }), }, tokens, refresh ); setForm({ current_password: "", new_password: "", confirm_password: "" }); setMessage("Password changed successfully."); } catch (e) { setError(String(e.message || e)); } finally { setBusy(false); } }; return (
Manage your personal account security settings.
{error &&