Smeltery
Get started

Alloy

v0.1

Errors and flash

props.errors is on every page: the errors of the previous request's failed validation, the first message per field ({ "email": "The email field must be a valid email address." }; Alloy::all_errors() sends arrays), and {} without errors. Inertia's client posts forms as JSON (as multipart/form-data when a file is in them), and the web stack answers an Inertia request whose Valid<T> fails, or whose handler returns Err(Error::validation(field, message)), with a 303 back and the errors in the session; useForm shows them as form.errors.email. With the X-Inertia-Error-Bag: login header the errors arrive as { "login": { … } }. A page prop named errors is an error in debug builds.

The page's flash (usePage().flash in the browser) holds every value the previous request flashed with session.flash(key, value) whose key does not start with _, any JSON value. Flash values are public like props: never flash secrets. Keys starting with _ (the framework's errors, old input, the intended URL) never reach a page.

CSRF needs nothing in the pages: the client reads the XSRF-TOKEN cookie (a masked token, new on every response, not HttpOnly) and sends it as X-XSRF-TOKEN. When the token does not match, an Inertia request gets a 303 back with flash.error = "The page expired. Please try again." instead of the 419 page, and its handler does not run.

↑↓ moveEnter openEsc close