LoginForm
src/lib/components/auth/LoginForm.svelte
Purpose
A self-contained login form that posts credentials to
/api/v1/auth/login and reacts to the backend auth config. When
enable_formauth is on it renders the username/password fields; when
enable_webauthn is on (and the browser supports WebAuthn) it renders a
PasskeyButton below the
form. Use it on the login page and inside the
SessionExpiredDialog.
Origin
Custom — Primebrick-written. Built on sveltekit-superforms + Zod,
the shadcn-svelte™ form/input/button/alert primitives, and the
custom Password input. Not vendored from any registry.
Usage
Default (login page)
Code
With error callback
Code
Inside the session-expired dialog
Code
The parent decides what to do on success — the login page redirects, while the session-expired dialog drains and retries pending requests.
Behavior
- Auth-config driven: reads
authConfigState(enable_formauth,enable_webauthn). The password form only renders when form auth is enabled; the passkey button only renders when WebAuthn is enabled and the browser supports it. - Validation: Zod schema requires non-empty
usernameandpassword; field-level errors are mapped from RFC7807issues. - Error display: a destructive
Alertshows the translated message set viasetMessage(e.g. invalid credentials, account locked with{minutes}interpolation). - User store: on success,
userProfileStore.set(data.user)is called beforeonsuccess.
Props
Full prop table: see API reference — loginform.
Key props:
onsuccess?: (data: { success: boolean; user: any }) => void— called after a successful login.onerror?: () => void— called when login fails (bad credentials, network error, etc.).