import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; import { changePassword } from '../api'; import './LoginPage.css'; function ChangePasswordPage() { const [currentPassword, setCurrentPassword] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(null); const { user, refreshUser } = useAuth(); const navigate = useNavigate(); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!currentPassword || !newPassword || !confirmPassword) { setError('Please fill in all fields'); return; } if (newPassword !== confirmPassword) { setError('New passwords do not match'); return; } if (newPassword.length < 8) { setError('New password must be at least 8 characters'); return; } if (newPassword === currentPassword) { setError('New password must be different from current password'); return; } setIsSubmitting(true); setError(null); try { await changePassword(currentPassword, newPassword); // Refresh user to clear must_change_password flag await refreshUser(); navigate('/', { replace: true }); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to change password'); } finally { setIsSubmitting(false); } } return (

Change Password

{user?.must_change_password && (

You must change your password before continuing

)}
{error && (
{error}
)}
setCurrentPassword(e.target.value)} placeholder="Enter current password" autoComplete="current-password" autoFocus disabled={isSubmitting} />
setNewPassword(e.target.value)} placeholder="Enter new password (min 8 characters)" autoComplete="new-password" disabled={isSubmitting} />
setConfirmPassword(e.target.value)} placeholder="Confirm new password" autoComplete="new-password" disabled={isSubmitting} />

Artifact storage and management system

); } export default ChangePasswordPage;