Skip to content

7.4 billion tokens per month. 34 free LLM providers. 635 free model endpoints. All behind one /v1 endpoint, plus any custom OpenAI-compatible endpoint. Smart routing, automatic failover, encrypted keys. Personal experimentation only.

TypeScript

feat(dashboard): field-level validation for key, custom-provider, license, and auth forms

Tashfeen42d2b32cb246
diff --git a/client/src/components/auth-gate.tsx b/client/src/components/auth-gate.tsx
index 507d36ec..c2209add 100644
--- a/client/src/components/auth-gate.tsx
+++ b/client/src/components/auth-gate.tsx
@@ -2,10 +2,15 @@ import { useEffect, useState, type ReactNode } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { apiFetch, setToken, UNAUTHORIZED_EVENT } from '@/lib/api'
import { Button } from '@/components/ui/button'
+import { FieldError } from '@/components/ui/field-error'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
+import { isEmail } from '@/lib/validate'
import { useI18n } from '@/i18n'
+// Matches the server rule (routes/auth.ts zod schema).
+const PASSWORD_MIN = 8
+
interface AuthStatus {
needsSetup: boolean
authenticated: boolean
@@ -26,11 +31,30 @@ function AuthForm({ mode, onAuthed }: { mode: 'setup' | 'login'; onAuthed: () =>
const [password, setPassword] = useState('')
const [error, setError] = useState('')
const [busy, setBusy] = useState(false)
+ const [attempted, setAttempted] = useState(false)
const isSetup = mode === 'setup'
+ // Inline field feedback; the server stays authoritative. Only the setup form
+ // enforces the password minimum client-side (an existing password of any
+ // length must still be able to log in).
+ const emailError = !email.trim()
+ ? t('validation.required')
+ : !isEmail(email)
+ ? t('validation.email')
+ : null
+ const passwordError = !password
+ ? t('validation.required')
+ : isSetup && password.length < PASSWORD_MIN
+ ? t('validation.passwordMin', { min: PASSWORD_MIN })
+ : null
+
async function submit(e: React.FormEvent) {
e.preventDefault()
+ if (emailError || passwordError) {
+ setAttempted(true)
+ return
+ }
setBusy(true)
setError('')
try {
@@ -60,7 +84,7 @@ function AuthForm({ mode, onAuthed }: { mode: 'setup' | 'login'; onAuthed: () =>
? t('auth.setupDescription')
: t('auth.loginDescription')}
</p>
- <form onSubmit={submit} className="space-y-3">
+ <form onSubmit={submit} className="space-y-3" noValidate>
<div className="space-y-1.5">
<Label className="text-xs" htmlFor="auth-email">{t('auth.email')}</Label>
<Input
@@ -70,7 +94,9 @@ function AuthForm({ mode, onAuthed }: { mode: 'setup' | 'login'; onAuthed: () =>
value={email}
onChange={e => setEmail(e.target.value)}
placeholder={t('auth.emailPlaceholder')}
+ aria-invalid={attempted && !!emailError}
/>
+ {attempted && <FieldError error={emailError} />}
</div>
<div className="space-y-1.5">
<Label className="text-xs" htmlFor="auth-password">{t('auth.password')}</Label>
@@ -81,10 +107,12 @@ function AuthForm({ mode, onAuthed }: { mode: 'setup' | 'login'; onAuthed: () =>
value={password}
onChange={e => setPassword(e.target.value)}
placeholder={isSetup ? t('auth.passwordPlaceholderSetup') : t('auth.passwordPlaceholderLogin')}
+ aria-invalid={attempted && !!passwordError}
/>
+ {attempted && <FieldError error={passwordError} />}
</div>
{error && <p className="text-destructive text-xs">{error}</p>}
- <Button type="submit" className="w-full" disabled={busy || !email || !password}>
+ <Button type="submit" className="w-full" disabled={busy}>
{busy ? (isSetup ? t('auth.creating') : t('auth.signingIn')) : isSetup ? t('auth.createAccount') : t('auth.signIn')}
</Button>
</form>
diff --git a/client/src/components/keys/custom-provider-section.tsx b/client/src/components/keys/custom-provider-section.tsx
index 04456ee3..94816a0d 100644
--- a/client/src/components/keys/custom-provider-section.tsx
+++ b/client/src/components/keys/custom-provider-section.tsx
@@ -6,6 +6,8 @@ import { Input } from '@/components/ui/input'
import { Textarea } from '@/components/ui/textarea'
import { Label } from '@/components/ui/label'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
+import { FieldError } from '@/components/ui/field-error'
+import { isHttpUrl } from '@/lib/validate'
import { useI18n } from '@/i18n'
// Split a free-text model field on commas / newlines into a clean id list,
@@ -31,6 +33,16 @@ export function CustomProviderSection() {
const models = customType === 'chat' ? parseModelList(model) : [model.trim()].filter(Boolean)
const multiple = customType === 'chat' && models.length > 1
+ // Field-level validation: submit stays clickable and reveals what is
+ // missing instead of being silently disabled.
+ const [attempted, setAttempted] = useState(false)
+ const baseUrlError = !baseUrl.trim()
+ ? t('validation.required')
+ : !isHttpUrl(baseUrl)
+ ? t('validation.url')
+ : null
+ const modelError = models.length === 0 ? t('validation.required') : null
+
const { data: embeddingsData } = useQuery<{ families: { family: string }[] }>({
queryKey: ['embeddings'],
queryFn: () => apiFetch('/api/embeddings'),
@@ -55,7 +67,11 @@ export function CustomProviderSection() {
const submit = (e: React.FormEvent) => {
e.preventDefault()
- if (!baseUrl || models.length === 0) return
+ if (baseUrlError || modelError) {
+ setAttempted(true)
+ return
+ }
+ setAttempted(false)
const common = {
baseUrl,
model: models[0],
@@ -130,7 +146,9 @@ export function CustomProviderSection() {
onChange={e => setBaseUrl(e.target.value)}
placeholder="http://127.0.0.1:11434/v1"
className="font-mono text-xs"
+ aria-invalid={attempted && !!baseUrlError}
/>
+ {attempted && <FieldError error={baseUrlError} />}
</div>
<div className="space-y-1.5">
<Label className="text-xs">{customType === 'chat' ? t('keys.customModels') : t('keys.customModel')}</Label>
@@ -140,7 +158,9 @@ export function CustomProviderSection() {
placeholder={modelPlaceholder}
rows={customType === 'chat' ? 2 : 1}
className="w-[200px] font-mono text-xs"
+ aria-invalid={attempted && !!modelError}
/>
+ {attempted && <FieldError error={modelError} />}
</div>
<div className="space-y-1.5">
<Label className="text-xs">{t('keys.customDisplayName')}</Label>
@@ -173,7 +193,7 @@ export function CustomProviderSection() {
className="w-[150px] font-mono text-xs"
/>
</div>
- <Button type="submit" size="sm" disabled={!baseUrl || models.length === 0 || addCustom.isPending}>
+ <Button type="submit" size="sm" disabled={addCustom.isPending}>
{addCustom.isPending ? t('keys.addingCustom') : addLabel}
</Button>
</form>
diff --git a/client/src/components/ui/field-error.tsx b/client/src/components/ui/field-error.tsx
new file mode 100644
index 00000000..6e9a797b
--- /dev/null
+++ b/client/src/components/ui/field-error.tsx
@@ -0,0 +1,11 @@
+// Inline field-level error line, paired with aria-invalid on the input. The
+// convention (from ModelDetailPage): errors appear after the field was
+// touched or a submit was attempted, never on first paint.
+export function FieldError({ error }: { error?: string | null }) {
+ if (!error) return null
+ return (
+ <p role="alert" className="text-xs text-destructive">
+ {error}
+ </p>
+ )
+}
diff --git a/client/src/i18n/locales/en.json b/client/src/i18n/locales/en.json
index ede4ac49..37facaf3 100644
--- a/client/src/i18n/locales/en.json
+++ b/client/src/i18n/locales/en.json
@@ -518,5 +518,11 @@
"groupActions": "Actions",
"groupModels": "Models",
"toggleTheme": "Toggle dark mode"
+ },
+ "validation": {
+ "required": "Required",
+ "url": "Enter a valid URL starting with http:// or https://",
+ "email": "Enter a valid email address",
+ "passwordMin": "At least {min} characters"
}
}
diff --git a/client/src/i18n/locales/es.json b/client/src/i18n/locales/es.json
index 7e287241..b09a37ed 100644
--- a/client/src/i18n/locales/es.json
+++ b/client/src/i18n/locales/es.json
@@ -518,5 +518,11 @@
"cooldown": "cooldown",
"recent_errors": "fallando"
}
+ },
+ "validation": {
+ "required": "Obligatorio",
+ "url": "Introduce una URL válida que empiece por http:// o https://",
+ "email": "Introduce una dirección de correo válida",
+ "passwordMin": "Al menos {min} caracteres"
}
}
diff --git a/client/src/i18n/locales/fr.json b/client/src/i18n/locales/fr.json
index 17d0a5dc..7aa3ebbd 100644
--- a/client/src/i18n/locales/fr.json
+++ b/client/src/i18n/locales/fr.json
@@ -518,5 +518,11 @@
"cooldown": "en cooldown",
"recent_errors": "en échec"
}
+ },
+ "validation": {
+ "required": "Obligatoire",
+ "url": "Saisissez une URL valide commençant par http:// ou https://",
+ "email": "Saisissez une adresse e-mail valide",
+ "passwordMin": "Au moins {min} caractères"
}
}
diff --git a/client/src/i18n/locales/it.json b/client/src/i18n/locales/it.json
index ecdc29c6..518f5dc5 100644
--- a/client/src/i18n/locales/it.json
+++ b/client/src/i18n/locales/it.json
@@ -518,5 +518,11 @@
"cooldown": "cooldown",
"recent_errors": "in errore"
}
+ },
+ "validation": {
+ "required": "Obbligatorio",
+ "url": "Inserisci un URL valido che inizi con http:// o https://",
+ "email": "Inserisci un indirizzo email valido",
+ "passwordMin": "Almeno {min} caratteri"
}
}
diff --git a/client/src/i18n/locales/pt-BR.json b/client/src/i18n/locales/pt-BR.json
index ddf308bb..0b5c0648 100644
--- a/client/src/i18n/locales/pt-BR.json
+++ b/client/src/i18n/locales/pt-BR.json
@@ -518,5 +518,11 @@
"cooldown": "cooldown",
"recent_errors": "falhando"
}
+ },
+ "validation": {
+ "required": "Obrigatório",
+ "url": "Insira uma URL válida começando com http:// ou https://",
+ "email": "Insira um endereço de e-mail válido",
+ "passwordMin": "Pelo menos {min} caracteres"
}
}
diff --git a/client/src/i18n/locales/zh-CN.json b/client/src/i18n/locales/zh-CN.json
index 8329c972..105d4fb3 100644
--- a/client/src/i18n/locales/zh-CN.json
+++ b/client/src/i18n/locales/zh-CN.json
@@ -518,5 +518,11 @@
"cooldown": "冷却中",
"recent_errors": "失败中"
}
+ },
+ "validation": {
+ "required": "必填",
+ "url": "请输入以 http:// 或 https:// 开头的有效 URL",
+ "email": "请输入有效的邮箱地址",
+ "passwordMin": "至少 {min} 个字符"
}
}
diff --git a/client/src/lib/validate.ts b/client/src/lib/validate.ts
new file mode 100644
index 00000000..cc3421b3
--- /dev/null
+++ b/client/src/lib/validate.ts
@@ -0,0 +1,16 @@
+// Tiny client-side field validators. Server-side validation stays the source
+// of truth; these only power inline field feedback before submit.
+
+export function isHttpUrl(value: string): boolean {
+ try {
+ const u = new URL(value.trim())
+ return u.protocol === 'http:' || u.protocol === 'https:'
+ } catch {
+ return false
+ }
+}
+
+// Deliberately loose: enough to catch "no @" or trailing dots, not RFC 5322.
+export function isEmail(value: string): boolean {
+ return /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(value.trim())
+}
diff --git a/client/src/pages/KeysPage.tsx b/client/src/pages/KeysPage.tsx
index 7a03f9fb..19dd63cb 100644
--- a/client/src/pages/KeysPage.tsx
+++ b/client/src/pages/KeysPage.tsx
@@ -12,6 +12,7 @@ import { PageHeader } from '@/components/page-header'
import type { ApiKey, ApiKeyModel, Platform } from '../../../shared/types'
import { ChevronDown, KeyRound, Pencil, Trash2 } from 'lucide-react'
import { EmptyState } from '@/components/empty-state'
+import { FieldError } from '@/components/ui/field-error'
import { TableSkeleton } from '@/components/ui/skeleton'
import { formatSqliteUtcToLocalTime } from '@/lib/utils'
import { useI18n } from '@/i18n'
@@ -171,11 +172,20 @@ export default function KeysPage() {
const needsAccountId = platform === 'cloudflare'
const isKeyless = PLATFORMS.find(p => p.value === platform)?.keyless ?? false
+ // Field-level validation: the submit stays clickable and reveals what is
+ // missing instead of being silently disabled.
+ const [addAttempted, setAddAttempted] = useState(false)
+ const platformError = !platform ? t('validation.required') : null
+ const keyError = !isKeyless && !apiKey.trim() ? t('validation.required') : null
+ const accountIdError = needsAccountId && !accountId.trim() ? t('validation.required') : null
+
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
- if (!platform) return
- if (!isKeyless && !apiKey) return
- if (needsAccountId && !accountId) return
+ if (platformError || keyError || accountIdError) {
+ setAddAttempted(true)
+ return
+ }
+ setAddAttempted(false)
// Keyless providers submit an empty key; the backend stores a sentinel.
const key = isKeyless ? '' : (needsAccountId ? `${accountId}:${apiKey}` : apiKey)
addKey.mutate({ platform, key, label: label || undefined })
@@ -253,7 +263,7 @@ export default function KeysPage() {
<div className="space-y-1.5">
<Label className="text-xs">{t('keys.platform')}</Label>
<Select value={platform} onValueChange={(v) => setPlatform(v as Platform)}>
- <SelectTrigger className="w-[220px]">
+ <SelectTrigger className="w-[220px]" aria-invalid={addAttempted && !!platformError}>
<SelectValue placeholder={t('keys.selectPlatform')} />
</SelectTrigger>
<SelectContent>
@@ -262,6 +272,7 @@ export default function KeysPage() {
))}
</SelectContent>
</Select>
+ {addAttempted && <FieldError error={platformError} />}
{(() => {
const sel = PLATFORMS.find(p => p.value === platform)
return sel?.url ? <div className="pt-0.5"><GetKeyLink url={sel.url} /></div> : null
@@ -275,7 +286,9 @@ export default function KeysPage() {
onChange={e => setAccountId(e.target.value)}
placeholder="a1b2c3d4…"
className="w-[200px] font-mono text-xs"
+ aria-invalid={addAttempted && !!accountIdError}
/>
+ {addAttempted && <FieldError error={accountIdError} />}
</div>
)}
<div className="space-y-1.5 flex-1 min-w-[240px]">
@@ -287,7 +300,9 @@ export default function KeysPage() {
placeholder={isKeyless ? t('keys.noKeyNeededPlaceholder') : (needsAccountId ? t('keys.bearerTokenPlaceholder') : t('keys.pasteKeyPlaceholder'))}
className="font-mono text-xs"
disabled={isKeyless}
+ aria-invalid={addAttempted && !!keyError}
/>
+ {addAttempted && <FieldError error={keyError} />}
{isKeyless && (
<p className="text-[11px] text-muted-foreground">
{t('keys.keylessHint')}
@@ -303,7 +318,7 @@ export default function KeysPage() {
placeholder={t('keys.customDisplayNameOptional')}
className="w-[160px]"
/>
- <Button type="submit" size="sm" disabled={!platform || (!isKeyless && !apiKey) || (needsAccountId && !accountId) || addKey.isPending}>
+ <Button type="submit" size="sm" disabled={addKey.isPending}>
{addKey.isPending ? t('keys.adding') : isKeyless ? t('keys.enable') : t('keys.addKey')}
</Button>
</div>
diff --git a/client/src/pages/PremiumPage.tsx b/client/src/pages/PremiumPage.tsx
index b5871686..73f02bb1 100644
--- a/client/src/pages/PremiumPage.tsx
+++ b/client/src/pages/PremiumPage.tsx
@@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Badge } from '@/components/ui/badge'
+import { FieldError } from '@/components/ui/field-error'
import { CardSkeleton } from '@/components/ui/skeleton'
import { useI18n } from '@/i18n'
@@ -50,6 +51,7 @@ export default function PremiumPage() {
const { t } = useI18n()
const queryClient = useQueryClient()
const [keyInput, setKeyInput] = useState('')
+ const [activateAttempted, setActivateAttempted] = useState(false)
const { data, isLoading } = useQuery<PremiumStatus>({
queryKey: ['premium'],
@@ -205,7 +207,12 @@ export default function PremiumPage() {
className="flex flex-wrap items-end gap-3"
onSubmit={(e) => {
e.preventDefault()
- if (keyInput.trim()) activate.mutate(keyInput.trim())
+ if (!keyInput.trim()) {
+ setActivateAttempted(true)
+ return
+ }
+ setActivateAttempted(false)
+ activate.mutate(keyInput.trim())
}}
>
<div className="space-y-1.5 flex-1 min-w-[260px]">
@@ -216,9 +223,11 @@ export default function PremiumPage() {
placeholder="fla_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
className="font-mono text-xs"
autoComplete="off"
+ aria-invalid={activateAttempted && !keyInput.trim()}
/>
+ {activateAttempted && !keyInput.trim() && <FieldError error={t('validation.required')} />}
</div>
- <Button type="submit" size="sm" disabled={!keyInput.trim() || activate.isPending}>
+ <Button type="submit" size="sm" disabled={activate.isPending}>
{activate.isPending ? t('premium.activating') : t('premium.activate')}
</Button>
</form>