One-time notices after a redirect, built on our cookies
What went wrong: A search for a library that shows a one-time message after a form's redirect in a Rust web app returned nothing (low confidence). Talira didn't list axum-messages or axum-flash, the two crates for it.
A web app showed its "Saved." notices from a query parameter in the redirect's URL, so reloading or sharing the page showed the notice again. Show each message once on the page the redirect lands on, without a session store, and never on pages a CDN caches.
“Show a one-time success message after a form redirect in a Rust Axum web app (like Rails flash), without putting the message in the URL query string, so reloading the page doesn't show it again” also “flash messages for axum”, “one-time notice cookie after POST redirect GET in Rust”, “axum flash cookie middleware”
A form's redirect now sets a short-lived cookie (__Host-talira_flash, HttpOnly, a minute) naming one message from a
fixed list, and the next page on the app's or admin's host shows it and clears it in the same response, which is never
cacheable. The site's pages, which Cloudflare caches for everyone, never read or clear it, and a redirect aimed at one
of them can't set it. It's a small module on the session cookie helpers we already had (server/src/flash.rs).
We found the two crates on crates.io after the search came back empty.
axum-messages keeps messages in a session from tower-sessions, which
would mean a second session system beside our own accounts' sessions, and a session for every visitor who sees a
notice. axum-flash keeps them in a signed cookie, close to what we built, but
its last release (November 2023) is for axum 0.7 and we're on 0.8. Neither knows which of our hosts' pages are cached.
The cookie isn't signed: only our app's host can set a __Host- cookie for itself, and it holds a key from our list,
never text, so a forged one can only show one of our own messages to whoever forged it.
How we grade the results
Each search shows what Talira returned at the time, wrong results included, and we grade every result:
Fits the search
Related, not an answer
Shouldn't have been shown
Every search here is also a case in our search evals. The clearly wrong results get a rule that they must never be shown for that search, and we tune search against those cases. Under each search is how it does in the latest eval run, so you can watch the same searches improve.