From 0f3119d0d0a0d710065f568d6c97adba9851af0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kai=20B=C3=B6hm?= Date: Sat, 7 Nov 2026 06:42:46 +0000 Subject: [PATCH] Teen role with own passkey, pictures for older children (26.11.19) Teens sign in with a passkey on their own phone and may wish with a veto, shop, cook and rate, but not plan or edit dishes. Permissions now live as allow-lists in lib/auth/roles.ts. Children's pictures gain a set for older kids and initials; picture and PIN can be changed later. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q --- CLAUDE.md | 16 +- OlaresManifest.yaml | 4 +- app/(app)/kochen/[id]/page.tsx | 3 +- app/(app)/layout.tsx | 2 +- app/(app)/page.tsx | 10 +- app/(app)/plan/layout.tsx | 6 +- app/(app)/plan/page.tsx | 4 +- app/(app)/runde/layout.tsx | 4 +- app/api/auth/invite/verify/route.ts | 4 +- app/api/household/invitations/route.ts | 3 +- app/api/shopping/events/route.ts | 3 +- app/api/shopping/route.ts | 3 +- app/api/slots/[id]/cooked/route.ts | 3 +- components/app-nav.tsx | 14 +- components/avatar.tsx | 59 +++++++- components/kids/kid-picker.tsx | 4 +- components/more/invite-panel.tsx | 2 +- components/more/kids-admin.tsx | 198 ++++++++++++++++++++----- db/migrations/0010_teen_role.sql | 7 + e2e/kinder.spec.ts | 44 ++++++ lib/auth/invitations.ts | 2 +- lib/auth/roles.ts | 14 ++ lib/auth/schemas.ts | 2 +- lib/auth/session.ts | 10 +- lib/avatars.ts | 18 ++- lib/shopping-route.ts | 5 +- lib/wishes.ts | 4 +- messages/de.json | 31 +++- messages/en.json | 31 +++- messages/es.json | 31 +++- messages/fr.json | 31 +++- olares/Chart.yaml | 4 +- olares/OlaresManifest.yaml | 4 +- olares/markt/26.11.19.md | 5 + 34 files changed, 477 insertions(+), 108 deletions(-) create mode 100644 db/migrations/0010_teen_role.sql create mode 100644 lib/auth/roles.ts create mode 100644 olares/markt/26.11.19.md diff --git a/CLAUDE.md b/CLAUDE.md index 5962667..177209a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -7,11 +7,12 @@ > **Plattform:** Olares One (Kubernetes), Repo und CI auf Gitea — kein Supabase, > kein Vercel (E-0001). Eigene Gestaltung, nicht AImighty (E-0002). > Verteilung über den Markt, Repo öffentlich (E-0005). -> **Status:** 26.11.17 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut: +> **Status:** 26.11.19 — alle neun Arbeitspakete aus `docs/PROJEKTSTART.md` sind gebaut: > Anmeldung (Passkeys, Kinder mit Gerät + PIN), Gerichte (Link, Kochbuchfoto, AI über den > Olares Router), Wünschen, Plan, Einkaufsliste (Echtzeit, offline), Kochmodus mit > Bewertung, Web-App; Einzahl bei Stück-Mengen (26.11.15), Preise und Kosten mit Ampel -> (V2a, 26.11.16), Olares Router als Standard (26.11.17). Offen sind V2b (Kassenbons) +> (V2a, 26.11.16), Olares Router als Standard (26.11.17), untere Leiste am iPhone (26.11.18), +> Rolle „Jugendlich“ (26.11.19). Offen sind V2b (Kassenbons) > und der Magic Link. > **Letzte Aktualisierung:** 7. November 2026 @@ -323,6 +324,17 @@ Vorlagen ersetzt. `tests/seed.test.ts` prüft die Dateien. Ein Haushalt `gerichte`, `mehr`, `runde`. Schreibende Routen lassen Kinder nur beim Wünschen zu (`WISHERS`), ein Veto nie. +## Rollen + +- `admin`, `member`, `teen` (seit 26.11.19), `child`, `guest`. Wer was darf, steht nur + in `lib/auth/roles.ts` als Erlaubnisliste (`PLANNERS`, `SHOPPERS`, `COOKS`, + `WITH_PASSKEY`; `WISHERS` in `lib/wishes.ts`) — eine neue Rolle darf nichts, bis sie + dort steht. Jugendliche: Passkey auf dem eigenen Handy (Einladung mit Rolle + „Jugendlich“), wünschen mit Veto, einkaufen, kochen, bewerten; nicht planen + (`requirePlanner`), keine Gerichte pflegen, nichts verwalten. +- Kinderbilder (`lib/avatars.ts`): Tiere „für Kleine“, Hobbys und `initials` „für + Größere“; Bild und PIN lassen sich in „Mehr“ ändern. + ## Untere Leiste am iPhone - iOS lässt eine feste Leiste nach dem Schließen der Tastatur oft dort stehen, wo die diff --git a/OlaresManifest.yaml b/OlaresManifest.yaml index 00f6c82..bf4104b 100644 --- a/OlaresManifest.yaml +++ b/OlaresManifest.yaml @@ -21,7 +21,7 @@ metadata: title: What's cooking? description: The family decides together what's for dinner — and the shopping list writes itself. Runs entirely on your own box. icon: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png - version: 26.11.18 + version: 26.11.19 categories: - Applications @@ -61,7 +61,7 @@ permission: appData: true spec: - versionName: '26.11.18' + versionName: '26.11.19' featuredImage: https://git.aimighty.olares.de/aimighty/bilder/raw/branch/main/lunch/icon.png promoteImage: diff --git a/app/(app)/kochen/[id]/page.tsx b/app/(app)/kochen/[id]/page.tsx index 73816ac..9b91ca8 100644 --- a/app/(app)/kochen/[id]/page.tsx +++ b/app/(app)/kochen/[id]/page.tsx @@ -1,3 +1,4 @@ +import { can, COOKS } from "@/lib/auth/roles"; import { notFound, redirect } from "next/navigation"; import { getLocale, getTranslations } from "next-intl/server"; import { CookingMode } from "@/components/cooking/cooking-mode"; @@ -31,7 +32,7 @@ export default async function CookingPage({ params }: { params: Promise<{ id: st portions={slot.portions} ingredients={slot.dish.ingredients} steps={slot.dish.steps} - canFinish={session.role === "admin" || session.role === "member"} + canFinish={can(COOKS, session.role)} /> )} diff --git a/app/(app)/layout.tsx b/app/(app)/layout.tsx index 4de2e74..c1c4b86 100644 --- a/app/(app)/layout.tsx +++ b/app/(app)/layout.tsx @@ -11,7 +11,7 @@ export default async function AppLayout({ children }: { children: React.ReactNod return ( <>
{children}
- + ); } diff --git a/app/(app)/page.tsx b/app/(app)/page.tsx index ba14a21..314db73 100644 --- a/app/(app)/page.tsx +++ b/app/(app)/page.tsx @@ -1,3 +1,4 @@ +import { can, COOKS, PLANNERS } from "@/lib/auth/roles"; import { ChefHat, CookingPot, Crown, Heart } from "lucide-react"; import { RateCard } from "@/components/cooking/rate-card"; import { InstallHint } from "@/components/install-hint"; @@ -38,7 +39,8 @@ export default async function TodayPage() { ); return { round, entries, titles, budget: await budget(c, round.id, session.memberId) }; }); - const adult = session.role === "admin" || session.role === "member"; + const adult = can(PLANNERS, session.role); + const cook = can(COOKS, session.role); const day = data.round?.shoppingDate ? new Intl.DateTimeFormat(locale, { weekday: "long" }).format(new Date(`${data.round.shoppingDate}T12:00:00`)) : null; @@ -64,7 +66,7 @@ export default async function TodayPage() {

))} {"slots" in data && data.slots ? ( - + ) : "budget" in data && data.budget ? ( <>
@@ -139,7 +141,7 @@ async function FamilyWishes({ ); } -async function PlanToday({ slots, adult }: { slots: Awaited>; adult: boolean }) { +async function PlanToday({ slots, adult, cook }: { slots: Awaited>; adult: boolean; cook: boolean }) { const t = await getTranslations("today"); const next = slots.find((s) => s.dishId && !s.cookedAt); return ( @@ -157,7 +159,7 @@ async function PlanToday({ slots, adult }: { slots: Awaited - {adult ? t("startCooking") : t("readAlong")} + {cook ? t("startCooking") : t("readAlong")}
diff --git a/app/(app)/plan/layout.tsx b/app/(app)/plan/layout.tsx index 6b6e02f..cffa636 100644 --- a/app/(app)/plan/layout.tsx +++ b/app/(app)/plan/layout.tsx @@ -1,7 +1,7 @@ -import { requireAdult } from "@/lib/auth/session"; +import { requirePlanner } from "@/lib/auth/session"; -// Kinder sehen nur „Heute“ und „Wünschen“ (Konzept, „Kindermodus“). +// Planen nur Erwachsene; Kinder und Jugendliche sehen den Plan auf „Heute“. export default async function AdultsOnly({ children }: { children: React.ReactNode }) { - await requireAdult(); + await requirePlanner(); return children; } diff --git a/app/(app)/plan/page.tsx b/app/(app)/plan/page.tsx index ce32137..28f53b8 100644 --- a/app/(app)/plan/page.tsx +++ b/app/(app)/plan/page.tsx @@ -3,7 +3,7 @@ import { getLocale, getTranslations } from "next-intl/server"; import { buttonVariants } from "@/components/ui/button"; import { PlanBoard, type SlotCost } from "@/components/plan/plan-board"; import { costOverview } from "@/lib/costs"; -import { requireAdult } from "@/lib/auth/session"; +import { requirePlanner } from "@/lib/auth/session"; import { withHousehold } from "@/lib/db"; import { listDishes } from "@/lib/dishes"; import { planSlots } from "@/lib/plan"; @@ -13,7 +13,7 @@ import { cn } from "@/lib/utils"; export const dynamic = "force-dynamic"; export default async function PlanPage() { - const session = await requireAdult(); + const session = await requirePlanner(); const t = await getTranslations("plan"); const locale = await getLocale(); const data = await withHousehold(session.householdId, async (c) => { diff --git a/app/(app)/runde/layout.tsx b/app/(app)/runde/layout.tsx index 6b6e02f..5bcd40b 100644 --- a/app/(app)/runde/layout.tsx +++ b/app/(app)/runde/layout.tsx @@ -1,7 +1,7 @@ -import { requireAdult } from "@/lib/auth/session"; +import { requirePlanner } from "@/lib/auth/session"; // Kinder sehen nur „Heute“ und „Wünschen“ (Konzept, „Kindermodus“). export default async function AdultsOnly({ children }: { children: React.ReactNode }) { - await requireAdult(); + await requirePlanner(); return children; } diff --git a/app/api/auth/invite/verify/route.ts b/app/api/auth/invite/verify/route.ts index f99bb26..3bc993d 100644 --- a/app/api/auth/invite/verify/route.ts +++ b/app/api/auth/invite/verify/route.ts @@ -15,7 +15,7 @@ type InviteContext = { isNew: boolean; name: string; householdId: string; - role: "admin" | "member"; + role: "admin" | "member" | "teen"; }; // Einladung annehmen, Schritt 2: Passkey prüfen, die Einladung verbrauchen @@ -47,7 +47,7 @@ export async function POST(request: Request) { ctx.memberId, ctx.householdId, ctx.name, - ctx.role === "admin" ? "admin" : "member", + ctx.role === "admin" || ctx.role === "teen" ? ctx.role : "member", resolveLocale((await cookies()).get(LOCALE_COOKIE)?.value, request.headers.get("accept-language")), ]); } diff --git a/app/api/household/invitations/route.ts b/app/api/household/invitations/route.ts index 37b0fb2..32b39b4 100644 --- a/app/api/household/invitations/route.ts +++ b/app/api/household/invitations/route.ts @@ -1,3 +1,4 @@ +import { can, WITH_PASSKEY } from "@/lib/auth/roles"; import { withAuth, withHousehold } from "@/lib/db"; import { fail, json, readJson, sameOrigin } from "@/lib/auth/http"; import { createInvitationBody } from "@/lib/auth/schemas"; @@ -20,7 +21,7 @@ export async function POST(request: Request) { const body = createInvitationBody.safeParse(await readJson(request)); if (!body.success) return fail("invalid", 400); if (body.data.kind === "person" && session.role !== "admin") return fail("forbidden", 403); - if (session.role === "child" || session.role === "guest") return fail("forbidden", 403); + if (!can(WITH_PASSKEY, session.role)) return fail("forbidden", 403); const token = randomToken(); const data = body.data; diff --git a/app/api/shopping/events/route.ts b/app/api/shopping/events/route.ts index be81db1..d768bca 100644 --- a/app/api/shopping/events/route.ts +++ b/app/api/shopping/events/route.ts @@ -1,3 +1,4 @@ +import { can, SHOPPERS } from "@/lib/auth/roles"; import { guardRead, isResponse } from "@/lib/auth/guard"; import { fail } from "@/lib/auth/http"; import { subscribe } from "@/lib/shopping-events"; @@ -9,7 +10,7 @@ export const dynamic = "force-dynamic"; export async function GET(request: Request) { const session = await guardRead(); if (isResponse(session)) return session; - if (session.role === "child" || session.role === "guest") return fail("forbidden", 403); + if (!can(SHOPPERS, session.role)) return fail("forbidden", 403); const encoder = new TextEncoder(); let cleanup = () => {}; const stream = new ReadableStream({ diff --git a/app/api/shopping/route.ts b/app/api/shopping/route.ts index c9d6e3b..ef93f5b 100644 --- a/app/api/shopping/route.ts +++ b/app/api/shopping/route.ts @@ -1,3 +1,4 @@ +import { can, SHOPPERS } from "@/lib/auth/roles"; import { getLocale } from "next-intl/server"; import { guardRead, isResponse } from "@/lib/auth/guard"; import { fail, json } from "@/lib/auth/http"; @@ -11,7 +12,7 @@ export const dynamic = "force-dynamic"; export async function GET() { const session = await guardRead(); if (isResponse(session)) return session; - if (session.role === "child" || session.role === "guest") return fail("forbidden", 403); + if (!can(SHOPPERS, session.role)) return fail("forbidden", 403); const locale = await getLocale(); return withHousehold(session.householdId, async (c) => { const round = await currentRound(c); diff --git a/app/api/slots/[id]/cooked/route.ts b/app/api/slots/[id]/cooked/route.ts index 7700cd1..11e9100 100644 --- a/app/api/slots/[id]/cooked/route.ts +++ b/app/api/slots/[id]/cooked/route.ts @@ -1,3 +1,4 @@ +import { COOKS } from "@/lib/auth/roles"; import { guardWrite, isResponse } from "@/lib/auth/guard"; import { fail, json } from "@/lib/auth/http"; import { markCooked } from "@/lib/cooking"; @@ -8,7 +9,7 @@ export const dynamic = "force-dynamic"; // „Fertig“ im Kochmodus: Slot gekocht, Bewertung kann beginnen. export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) { - const session = await guardWrite(request); + const session = await guardWrite(request, [...COOKS]); if (isResponse(session)) return session; const { id } = await params; if (!/^[0-9a-f-]{36}$/.test(id)) return fail("invalid", 400); diff --git a/components/app-nav.tsx b/components/app-nav.tsx index b4d8e57..16fcf71 100644 --- a/components/app-nav.tsx +++ b/components/app-nav.tsx @@ -18,17 +18,27 @@ const ITEMS = [ { href: "/mehr", key: "more", icon: Ellipsis }, ] as const; +// Jugendliche: wünschen statt planen, dazu Einkauf, Gerichte (lesen) und Mehr. +const TEEN_ITEMS = [ + { href: "/", key: "today", icon: Sun }, + { href: "/wuenschen", key: "wish", icon: Coins }, + { href: "/einkauf", key: "shopping", icon: ShoppingCart }, + { href: "/gerichte", key: "dishes", icon: UtensilsCrossed }, + { href: "/mehr", key: "more", icon: Ellipsis }, +] as const; + // Kinder: „Heute“, „Wünschen“ und „Wechseln“ (zurück zur Bildauswahl am Kindergerät). const CHILD_ITEMS = [ { href: "/", key: "today", icon: Sun }, { href: "/wuenschen", key: "wish", icon: Coins }, ] as const; -export function AppNav({ child = false }: { child?: boolean }) { +export function AppNav({ variant = "adult" }: { variant?: "adult" | "teen" | "child" }) { + const child = variant === "child"; const t = useTranslations("nav"); const path = usePathname(); const router = useRouter(); - const items = child ? CHILD_ITEMS : ITEMS; + const items = child ? CHILD_ITEMS : variant === "teen" ? TEEN_ITEMS : ITEMS; // Beim Tippen weg, danach unten am sichtbaren Bereich (iOS, lib/use-keyboard-nav.ts). const { ref, typing } = useKeyboardSafeNav(); return ( diff --git a/components/avatar.tsx b/components/avatar.tsx index dbc6754..dacab2f 100644 --- a/components/avatar.tsx +++ b/components/avatar.tsx @@ -1,9 +1,62 @@ -import { Bird, Cat, Dog, Fish, Rabbit, Snail, Squirrel, Turtle, UserRound } from "lucide-react"; +import { + Bike, + Bird, + Camera, + Cat, + Dog, + Fish, + Flame, + Gamepad2, + Guitar, + Headphones, + Mountain, + Palette, + Rabbit, + Rocket, + Snail, + Squirrel, + Trophy, + Turtle, + UserRound, + Volleyball, +} from "lucide-react"; +import { initials } from "@/lib/avatars"; import { cn } from "@/lib/utils"; -const ICONS = { cat: Cat, dog: Dog, rabbit: Rabbit, bird: Bird, fish: Fish, turtle: Turtle, squirrel: Squirrel, snail: Snail }; +const ICONS = { + cat: Cat, + dog: Dog, + rabbit: Rabbit, + bird: Bird, + fish: Fish, + turtle: Turtle, + squirrel: Squirrel, + snail: Snail, + gamepad: Gamepad2, + headphones: Headphones, + guitar: Guitar, + volleyball: Volleyball, + bike: Bike, + camera: Camera, + palette: Palette, + rocket: Rocket, + mountain: Mountain, + trophy: Trophy, + flame: Flame, +}; -export function AvatarIcon({ avatar, className }: { avatar: string | null; className?: string }) { +/** Bild einer Person; „initials“ zeigt die Anfangsbuchstaben (ohne Namen: „Aa“ als Muster). */ +export function AvatarIcon({ avatar, name, className }: { avatar: string | null; name?: string; className?: string }) { + if (avatar === "initials") { + return ( + + + 1 ? 15 : 18} fontWeight="600" fill="currentColor"> + {name ? initials(name) || "?" : "Aa"} + + + ); + } const Icon = (avatar && ICONS[avatar as keyof typeof ICONS]) || UserRound; return ; } diff --git a/components/kids/kid-picker.tsx b/components/kids/kid-picker.tsx index 454f17f..8669860 100644 --- a/components/kids/kid-picker.tsx +++ b/components/kids/kid-picker.tsx @@ -55,7 +55,7 @@ export function KidPicker({ kids }: { kids: Child[] }) { className="flex w-full flex-col items-center gap-3 rounded-3xl bg-muted p-5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" > - + {k.name} @@ -68,7 +68,7 @@ export function KidPicker({ kids }: { kids: Child[] }) { return (
- +

{t("hello", { name: chosen.name })}

diff --git a/components/more/invite-panel.tsx b/components/more/invite-panel.tsx index 2e4dd8e..20c8650 100644 --- a/components/more/invite-panel.tsx +++ b/components/more/invite-panel.tsx @@ -76,7 +76,7 @@ export function InvitePerson() {

{t("inviteRole")} - {(["member", "admin"] as const).map((role) => ( + {(["member", "teen", "admin"] as const).map((role) => (