import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext.jsx'; import { useToast } from '../contexts/ToastContext.jsx'; import { api } from '../utils/api.js'; export default function ChangePassword() { const [current, setCurrent] = useState(''); const [next, setNext] = useState(''); const [confirm, setConfirm] = useState(''); const [loading, setLoading] = useState(false); const { setMustChangePassword } = useAuth(); const toast = useToast(); const nav = useNavigate(); const submit = async (e) => { e.preventDefault(); if (next !== confirm) return toast('Passwords do not match', 'error'); if (next.length < 8) return toast('Password must be at least 8 characters', 'error'); setLoading(true); try { await api.changePassword({ currentPassword: current, newPassword: next }); setMustChangePassword(false); toast('Password changed!', 'success'); nav('/'); } catch (err) { toast(err.message, 'error'); } finally { setLoading(false); } }; return (

Change Password

You must set a new password before continuing.

setCurrent(e.target.value)} autoComplete="new-password" required />
setNext(e.target.value)} autoComplete="new-password" required />
setConfirm(e.target.value)} autoComplete="new-password" required />
); }