[]previous and next page

setFlash

Sets a value that the next page shows once, read with useFlash() on the page.

Sets a value that the next page shows once, read with useFlash() on the page. Use it for a message that must survive a redirect (for example "Saved."). The value must be serializable (the wire codec: dates, maps, sets, bigints and plain data). Needs security.cookieSecrets.

Import#

ts
import { setFlash } from "@shadow-js/dusk/server";

Signature#

ts
async function setFlash(event: RequestEvent, value: unknown): Promise<void>

Parameters#

Name Description
event The request event of the function or the route.
value What the page reads. Keep it small: payloads over 3000 characters keep only the status.

Returns#

A promise that resolves when the cookie is set.

Throws#

  • COOKIE_SECRET_MISSING error when no cookie secrets are configured.

Examples#

ts
export const archive = serverFn({ form: true }, async (input, event) => {
  await archiveNote(input.id);
  await setFlash(event, { notice: "Archived." });
  return { ok: true };
});