import { useState } from 'react'; import { apiFetch } from '../lib/api'; import { useI18n } from '../lib/i18n'; import { useAuth } from '../lib/auth'; type Props = { open: boolean; promptText: string; onCancel: () => void; onReveal: (apiKey: string) => void; onSetPasswordClick: () => void; }; export default function PasswordRevealPrompt({ open, promptText, onCancel, onReveal, onSetPasswordClick }: Props) { const { t } = useI18n(); const { user } = useAuth(); const hasPassword = user?.hasPassword !== false; const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); if (!open) return null; const submit = async () => { setLoading(true); setError(''); try { const data = await apiFetch<{ apiKey: string }>('/auth/api-key/reveal', { method: 'POST', body: JSON.stringify({ password }), }); onReveal(data.apiKey); setPassword(''); } catch (err) { setError(err instanceof Error ? err.message : 'Verification failed'); } finally { setLoading(false); } }; if (!hasPassword) { return (
{t('dashboard.settings.setPasswordToReveal')}
{promptText}
setPassword(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter' && password) submit(); }} className="input-base" placeholder={t('dashboard.settings.currentPassword')} autoFocus /> {error &&{error}
}