import { useMemo, useState } from 'preact/hooks'; import { AlertTriangle, Copy, RefreshCw } from 'lucide-preact'; import StandalonePageFrame from '@/components/StandalonePageFrame'; import { t } from '@/lib/i18n'; interface JwtWarningPageProps { reason: 'missing' | 'default' | 'too_short'; minLength: number; } export default function JwtWarningPage(props: JwtWarningPageProps) { const [seed, setSeed] = useState(0); const [copyHint, setCopyHint] = useState(''); const generatedSecret = useMemo(() => generateJwtSecret(32), [seed]); const title = props.reason === 'missing' ? t('txt_jwt_title_missing') : props.reason === 'default' ? t('txt_jwt_title_default') : t('txt_jwt_title_too_short'); const isMissing = props.reason === 'missing'; const fixTitle = isMissing ? t('txt_jwt_how_to_fix_add') : t('txt_jwt_how_to_fix_replace'); const fixStep1 = isMissing ? t('txt_jwt_add_step_1') : t('txt_jwt_replace_step_1', { min: props.minLength }); const fixStep2 = isMissing ? t('txt_jwt_add_step_2') : t('txt_jwt_replace_step_2'); const fixStep3 = isMissing ? t('txt_jwt_add_step_3') : t('txt_jwt_replace_step_3'); return (
{t('txt_jwt_warning_subtitle')}
{fixTitle}
  1. {fixStep1}
  2. {fixStep2}
  3. {fixStep3}
{t('txt_random_secret_generator')}
{copyHint && {copyHint}}
); } function generateJwtSecret(length: number): string { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; const bytes = crypto.getRandomValues(new Uint8Array(length)); let out = ''; for (let i = 0; i < length; i += 1) { out += chars[bytes[i] % chars.length]; } return out; }