import { useState, type FormEvent } from 'react' import type { ReauthCredentials } from './api/client' type ReauthModalProps = { title: string hint?: string requireTotp: boolean confirmLabel?: string onCancel: () => void onConfirm: (credentials: ReauthCredentials) => Promise } export function ReauthModal({ title, hint, requireTotp, confirmLabel = 'Confirm', onCancel, onConfirm, }: ReauthModalProps) { const [password, setPassword] = useState('') const [totpCode, setTotpCode] = useState('') const [error, setError] = useState(null) const [isSubmitting, setIsSubmitting] = useState(false) async function handleSubmit(event: FormEvent) { event.preventDefault() setError(null) setIsSubmitting(true) try { await onConfirm({ current_password: password, totp_code: totpCode, }) } catch (err) { setError(err instanceof Error ? err.message : 'Re-authentication failed') setIsSubmitting(false) } } return (

{title}

{hint ?

{hint}

: null}
void handleSubmit(event)}> setPassword(event.target.value)} required /> {requireTotp ? ( <> setTotpCode(event.target.value)} required /> ) : null} {error ? (

{error}

) : null}
) }