Every recipe can be presented in large type, portrait on the phone and side by side in landscape on a tablet or Echo Show: ingredients in the chosen portions, then step by step with per-step amounts and timers. Tap the left third to go back, anywhere else to go forward, or swipe; wake lock keeps the screen on. An admin unlocks a kitchen display with a one-time link (kid_devices with kind 'kitchen', cookie lunch_kueche). It has no session: it reads the next planned dishes and all recipes of its household, every other page leads to /kueche and every API answers 401. Kid sign-in only accepts kind 'kids'. Cooking mode and presentation share components/cooking/kit.tsx. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import "server-only";
|
|
import { withAuth } from "@/lib/db";
|
|
import { fail, sameOrigin } from "./http";
|
|
import { currentKitchenDisplay } from "./kids";
|
|
import { getSession, type Session } from "./session";
|
|
import { loadInstance } from "./webauthn";
|
|
|
|
type Role = Session["role"];
|
|
const WRITERS: Role[] = ["admin", "member"];
|
|
|
|
/**
|
|
* Für jede Route, die etwas ändert: Sitzung, Ursprung (CSRF) und Rolle prüfen.
|
|
* Gibt die Sitzung zurück oder die fertige Fehlerantwort.
|
|
*/
|
|
export async function guardWrite(request: Request, roles: Role[] = WRITERS): Promise<Session | Response> {
|
|
const session = await getSession();
|
|
if (!session) return fail("signedOut", 401);
|
|
const instance = await withAuth(loadInstance);
|
|
if (!instance || !sameOrigin(request, instance.origin)) return fail("origin", 403);
|
|
if (!roles.includes(session.role)) return fail("forbidden", 403);
|
|
return session;
|
|
}
|
|
|
|
/** Für lesende Routen: nur die Sitzung. */
|
|
export async function guardRead(): Promise<Session | Response> {
|
|
return (await getSession()) ?? fail("signedOut", 401);
|
|
}
|
|
|
|
/** Für Fotos: die Sitzung oder ein Küchendisplay — nur der Haushalt, nie eine Rolle. */
|
|
export async function readerHousehold(): Promise<string | Response> {
|
|
const session = await getSession();
|
|
if (session) return session.householdId;
|
|
return (await currentKitchenDisplay())?.householdId ?? fail("signedOut", 401);
|
|
}
|
|
|
|
export const isResponse = (x: unknown): x is Response => x instanceof Response;
|