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

fix(auth): a11y and viewport fixes on the sign-in gate (#1078)

Kaban1570009d6f06ff
diff --git a/client/src/components/auth-gate.tsx b/client/src/components/auth-gate.tsx
index 3bac7b86..5c3514b4 100644
--- a/client/src/components/auth-gate.tsx
+++ b/client/src/components/auth-gate.tsx
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState, type ReactNode } from 'react'
import { useQuery, useQueryClient } from '@tanstack/react-query'
+import { Loader2 } from 'lucide-react'
import { apiFetch, setToken, UNAUTHORIZED_EVENT, type ApiError } from '@/lib/api'
import { Button } from '@/components/ui/button'
import { FieldError } from '@/components/ui/field-error'
@@ -36,10 +37,12 @@ interface AuthStatus {
}
function Centered({ children }: { children: ReactNode }) {
+ // dvh, not vh: on mobile the collapsing URL bar and the software keyboard both
+ // change the viewport, and 100vh leaves the card parked mid-scroll.
return (
- <div className="min-h-screen flex items-center justify-center bg-background px-4">
+ <main className="min-h-dvh flex items-center justify-center bg-background px-4 py-10">
<div className="w-full max-w-sm">{children}</div>
- </div>
+ </main>
)
}
@@ -72,6 +75,9 @@ function AuthForm({ mode, onAuthed }: { mode: 'setup' | 'login'; onAuthed: () =>
? t('validation.passwordMin', { min: PASSWORD_MIN })
: null
+ const showEmailError = attempted && !!emailError
+ const showPasswordError = attempted && !!passwordError
+
async function submit(e: React.FormEvent) {
e.preventDefault()
if (emailError || passwordError) {
@@ -114,25 +120,27 @@ function AuthForm({ mode, onAuthed }: { mode: 'setup' | 'login'; onAuthed: () =>
<span className="font-semibold tracking-tight text-sm">FreeLLMAPI</span>
</div>
<div className="rounded-3xl border bg-card p-6">
- <h1 className="text-base font-medium">{isSetup ? t('auth.createYourAccount') : t('auth.signIn')}</h1>
- <p className="text-xs text-muted-foreground mt-1 mb-4">
+ <h1 className="text-lg font-semibold tracking-tight">{isSetup ? t('auth.createYourAccount') : t('auth.signIn')}</h1>
+ <p className="text-sm text-muted-foreground mt-1.5 mb-6">
{isSetup
? t('auth.setupDescription')
: t('auth.loginDescription')}
</p>
- <form onSubmit={submit} className="space-y-3" noValidate>
+ <form onSubmit={submit} className="space-y-4" noValidate>
<div className="space-y-1.5">
<Label className="text-xs" htmlFor="auth-email">{t('auth.email')}</Label>
<Input
id="auth-email"
type="email"
autoComplete="username"
+ autoFocus
value={email}
onChange={e => setEmail(e.target.value)}
placeholder={t('auth.emailPlaceholder')}
- aria-invalid={attempted && !!emailError}
+ aria-invalid={showEmailError}
+ aria-describedby={showEmailError ? 'auth-email-error' : undefined}
/>
- {attempted && <FieldError error={emailError} />}
+ {attempted && <FieldError id="auth-email-error" error={emailError} />}
</div>
<div className="space-y-1.5">
<Label className="text-xs" htmlFor="auth-password">{t('auth.password')}</Label>
@@ -143,9 +151,10 @@ 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}
+ aria-invalid={showPasswordError}
+ aria-describedby={showPasswordError ? 'auth-password-error' : undefined}
/>
- {attempted && <FieldError error={passwordError} />}
+ {attempted && <FieldError id="auth-password-error" error={passwordError} />}
</div>
{isSetup && codeRequired && (
<div className="space-y-1.5">
@@ -157,12 +166,20 @@ function AuthForm({ mode, onAuthed }: { mode: 'setup' | 'login'; onAuthed: () =>
value={setupCode}
onChange={e => setSetupCode(e.target.value)}
placeholder={t('auth.setupCodePlaceholder')}
+ aria-describedby="auth-setup-code-hint"
/>
- <p className="text-xs text-muted-foreground">{t('auth.setupCodeHint')}</p>
+ <p id="auth-setup-code-hint" className="text-xs text-muted-foreground">{t('auth.setupCodeHint')}</p>
</div>
)}
- {error && <p className="text-destructive text-xs">{error}</p>}
- <Button type="submit" className="w-full" disabled={busy}>
+ {/* A server rejection is the one error nobody can predict; it gets the same
+ announcement and the same visual weight as the inline field errors. */}
+ {error && (
+ <p role="alert" className="rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive">
+ {error}
+ </p>
+ )}
+ <Button type="submit" className="w-full h-10" disabled={busy}>
+ {busy && <Loader2 className="animate-spin" aria-hidden />}
{busy ? (isSetup ? t('auth.creating') : t('auth.signingIn')) : isSetup ? t('auth.createAccount') : t('auth.signIn')}
</Button>
</form>
@@ -465,11 +482,20 @@ export function AuthGate({ children }: { children: ReactNode }) {
refetch()
}
- if (isLoading) return <Centered><p className="text-sm text-muted-foreground text-center">{t('auth.loading')}</p></Centered>
+ if (isLoading) {
+ return (
+ <Centered>
+ <p className="flex items-center justify-center gap-2 text-sm text-muted-foreground">
+ <Loader2 className="size-3.5 animate-spin" aria-hidden />
+ {t('auth.loading')}
+ </p>
+ </Centered>
+ )
+ }
if (isError || !data) {
return (
<Centered>
- <div className="rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2.5 text-xs text-destructive">
+ <div role="alert" className="rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2.5 text-xs text-destructive">
{t('auth.serverUnreachableBefore')}<code className="font-mono">npm run dev</code>{t('auth.serverUnreachableAfter')}
</div>
</Centered>
diff --git a/client/src/components/ui/field-error.tsx b/client/src/components/ui/field-error.tsx
index 6e9a797b..ffc3fbec 100644
--- a/client/src/components/ui/field-error.tsx
+++ b/client/src/components/ui/field-error.tsx
@@ -1,10 +1,12 @@
// 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 }) {
+// An `id` lets the field point at this line with aria-describedby, so the
+// error is read as part of the input rather than only as a live announcement.
+export function FieldError({ id, error }: { id?: string; error?: string | null }) {
if (!error) return null
return (
- <p role="alert" className="text-xs text-destructive">
+ <p id={id} role="alert" className="text-xs text-destructive">
{error}
</p>
)