Guard
A guard: a check that runs before a server function's input is validated or its handler runs, and before an API route method's body is read.
A guard: a check that runs before a server function's input is validated or its handler runs, and
before an API route method's body is read. Return nothing (or true) to let the call through, return
false to refuse it with 403, or throw (an HttpError gives 401, 403 or any other status). A guard
sees the request only, not the input: the input is untrusted until its schema has accepted it.
Import#
ts
import type { Guard } from "@shadow-js/dusk/server";
Signature#
ts
type Guard = (event: RequestEvent) => void | boolean | Promise<void | boolean>
Examples#
ts
export const requireUser: Guard = (event) => {
if (event.locals.user === undefined) throw new HttpError(401, "Sign in first");
};