Own sign-in with passkeys, open the entrance, market entry (26.11.2)
ci / olares chart · sanity (pull_request) Successful in 3s
ci / app · types + tests + build (pull_request) Successful in 3m7s
markt / eintrag (pull_request) Successful in 29s
release / which version (pull_request) Successful in 3s
release / olares chart · sanity (pull_request) Successful in 4s
release / app (pull_request) Successful in 59s
release / tag and release (pull_request) Skipped

Setup with a code from /app/data, passkeys with required user
verification, sessions as hashed cookies bound to the passkey they
started with, single-use invitation and device links, removing a
passkey or a member, and a recovery code for the owner. Cross-household
lookups before sign-in run in withAuth() (app.auth), allowed only on the
sign-in tables; a test pins that list. State-changing routes check the
session and the Origin header.

Security check with the login-sicherheit skill before the first
invitation: docs/sicherheit/login-2026-11-06.md (no open findings above
low). Entrance goes public now that the own sign-in exists; markt.yml
creates the Lunch entry in aimighty-market and proves it with wrangler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q
This commit is contained in:
Kai BöhmandClaude Opus 5.5 committed 2026-11-06 19:26:36 +00:00
1 parent a62e48116a
commit f423dd67ce
71 files changed
+3573 -32

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
"use client";
import { Ellipsis, Sun } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useTranslations } from "next-intl";
import { cn } from "@/lib/utils";
// Untere Leiste unter dem Daumen (Leitprinzip 8). Plan, Einkauf und Gerichte
// kommen mit ihren Arbeitspaketen dazu.
const ITEMS = [
{ href: "/", key: "today", icon: Sun },
{ href: "/mehr", key: "more", icon: Ellipsis },
] as const;
export function AppNav() {
const t = useTranslations("nav");
const path = usePathname();
return (
<nav
aria-label="Navigation"
className="fixed inset-x-0 bottom-0 z-10 border-t border-border bg-background/95 pb-[env(safe-area-inset-bottom)] backdrop-blur-none"
>
<ul className="mx-auto flex max-w-md justify-around">
{ITEMS.map(({ href, key, icon: Icon }) => {
const active = href === "/" ? path === "/" : path.startsWith(href);
return (
<li key={key}>
<Link
href={href}
aria-current={active ? "page" : undefined}
className={cn(
"flex min-h-14 min-w-20 flex-col items-center justify-center gap-0.5 text-xs",
active ? "font-semibold text-primary" : "text-muted-foreground",
)}
>
<Icon aria-hidden className="size-6" strokeWidth={1.75} />
{t(key)}
</Link>
</li>
);
})}
</ul>
</nav>
);
}
+15
View File
@@ -0,0 +1,15 @@
import Image from "next/image";
// Rahmen für Einrichten, Anmelden und Einladung: Symbol, Titel, Text, Inhalt.
export function AuthShell({ title, intro, children }: { title: string; intro?: string; children?: React.ReactNode }) {
return (
<main className="mx-auto flex min-h-dvh w-full max-w-sm flex-col justify-center gap-6 px-4 py-10">
<div className="flex flex-col items-center gap-4 text-center">
<Image src="/icon.svg" alt="" width={64} height={64} priority />
<h1 className="text-2xl font-semibold">{title}</h1>
{intro ? <p className="text-muted-foreground">{intro}</p> : null}
</div>
{children}
</main>
);
}
+48
View File
@@ -0,0 +1,48 @@
"use client";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ErrorNotice } from "@/components/ui/notice";
import { register, type ErrorKey } from "./passkey";
export function InviteForm({ token, suggestedName, askName }: { token: string; suggestedName: string; askName: boolean }) {
const t = useTranslations("auth");
const router = useRouter();
const [error, setError] = useState<ErrorKey | null>(null);
const [busy, setBusy] = useState(false);
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
const form = new FormData(event.currentTarget);
setBusy(true);
setError(null);
const result = await register(
"/api/auth/invite/options",
askName ? { token, name: form.get("name") } : { token },
"/api/auth/invite/verify",
);
setBusy(false);
if (result) setError(result);
else router.replace("/");
}
return (
<form onSubmit={onSubmit} className="flex flex-col gap-4">
{askName ? (
<div className="flex flex-col gap-2">
<Label htmlFor="name">{t("invite.name")}</Label>
<Input id="name" name="name" required maxLength={60} defaultValue={suggestedName} autoComplete="given-name" />
</div>
) : null}
{error ? <ErrorNotice>{t(`errors.${error}`)}</ErrorNotice> : null}
<Button type="submit" size="lg" disabled={busy}>
{busy ? t("working") : t("invite.submit")}
</Button>
<p className="text-sm text-muted-foreground">{t("setup.passkeyHint")}</p>
</form>
);
}
+40
View File
@@ -0,0 +1,40 @@
"use client";
import { KeyRound } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { ErrorNotice } from "@/components/ui/notice";
import { signIn, type ErrorKey } from "./passkey";
export function LoginButton() {
const t = useTranslations("auth");
const router = useRouter();
const [error, setError] = useState<ErrorKey | null>(null);
const [busy, setBusy] = useState(false);
async function onClick() {
setBusy(true);
setError(null);
const result = await signIn();
setBusy(false);
if (result) setError(result);
else router.replace("/");
}
return (
<div className="flex flex-col gap-4">
{error ? <ErrorNotice>{t(`errors.${error}`)}</ErrorNotice> : null}
<Button size="lg" onClick={onClick} disabled={busy}>
<KeyRound aria-hidden />
{busy ? t("working") : t("login.submit")}
</Button>
<p className="text-sm text-muted-foreground">{t("login.noPasskey")}</p>
<Link href="/wiederherstellen" className="inline-flex min-h-11 items-center self-center text-sm underline underline-offset-4">
{t("login.lost")}
</Link>
</div>
);
}
+66
View File
@@ -0,0 +1,66 @@
"use client";
import {
browserSupportsWebAuthn,
startAuthentication,
startRegistration,
WebAuthnError,
} from "@simplewebauthn/browser";
// Der Ablauf im Browser: Optionen holen, Passkey vom Gerät, Antwort prüfen
// lassen. Gibt den Schlüssel eines Fehlers zurück (messages: auth.errors)
// oder null, wenn es geklappt hat.
export type ErrorKey =
| "code" | "tooMany" | "invalid" | "expired" | "passkey" | "cancelled"
| "unsupported" | "invitation" | "alreadySetUp" | "origin" | "forbidden" | "lastPasskey" | "unknown";
const KNOWN: readonly string[] = [
"code", "tooMany", "invalid", "expired", "passkey", "invitation", "alreadySetUp", "origin", "forbidden", "lastPasskey",
];
async function post(url: string, body: unknown): Promise<{ ok: boolean; data: Record<string, unknown> }> {
const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
const data = (await res.json().catch(() => ({}))) as Record<string, unknown>;
return { ok: res.ok, data };
}
function errorKey(data: Record<string, unknown>): ErrorKey {
const e = data.error;
return typeof e === "string" && KNOWN.includes(e) ? (e as ErrorKey) : "unknown";
}
function fromBrowser(error: unknown): ErrorKey {
if (error instanceof WebAuthnError && error.code === "ERROR_CEREMONY_ABORTED") return "cancelled";
if (error instanceof Error && error.name === "NotAllowedError") return "cancelled";
if (error instanceof WebAuthnError && error.code === "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED") return "passkey";
return "unknown";
}
export async function register(optionsUrl: string, body: unknown, verifyUrl: string): Promise<ErrorKey | null> {
if (!browserSupportsWebAuthn()) return "unsupported";
const first = await post(optionsUrl, body);
if (!first.ok) return errorKey(first.data);
let response;
try {
response = await startRegistration({ optionsJSON: first.data.options as never });
} catch (error) {
return fromBrowser(error);
}
const second = await post(verifyUrl, { challengeId: first.data.challengeId, response });
return second.ok ? null : errorKey(second.data);
}
export async function signIn(): Promise<ErrorKey | null> {
if (!browserSupportsWebAuthn()) return "unsupported";
const first = await post("/api/auth/login/options", {});
if (!first.ok) return errorKey(first.data);
let response;
try {
response = await startAuthentication({ optionsJSON: first.data.options as never });
} catch (error) {
return fromBrowser(error);
}
const second = await post("/api/auth/login/verify", { challengeId: first.data.challengeId, response });
return second.ok ? null : errorKey(second.data);
}
+56
View File
@@ -0,0 +1,56 @@
"use client";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ErrorNotice } from "@/components/ui/notice";
import { register, type ErrorKey } from "./passkey";
export function RecoveryForm() {
const t = useTranslations("auth");
const router = useRouter();
const [requested, setRequested] = useState(false);
const [error, setError] = useState<ErrorKey | null>(null);
const [busy, setBusy] = useState(false);
async function requestCode() {
setError(null);
const res = await fetch("/api/auth/recovery/request", { method: "POST" });
if (res.ok) setRequested(true);
else setError(res.status === 429 ? "tooMany" : "unknown");
}
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
const code = new FormData(event.currentTarget).get("code");
setBusy(true);
setError(null);
const result = await register("/api/auth/recovery/options", { code }, "/api/auth/recovery/verify");
setBusy(false);
if (result) setError(result);
else router.replace("/mehr");
}
return (
<div className="flex flex-col gap-4">
<Button type="button" variant={requested ? "outline" : "default"} size="lg" onClick={requestCode}>
{t("recovery.request")}
</Button>
{requested ? <p className="text-sm">{t("recovery.requested")}</p> : null}
<form onSubmit={onSubmit} className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="code">{t("recovery.code")}</Label>
<Input id="code" name="code" required autoComplete="one-time-code" autoCapitalize="characters" spellCheck={false} placeholder="XXXX-XXXX-XXXX-XXXX" />
</div>
{error ? <ErrorNotice>{t(`errors.${error}`)}</ErrorNotice> : null}
<Button type="submit" variant={requested ? "default" : "secondary"} size="lg" disabled={busy}>
{busy ? t("working") : t("recovery.submit")}
</Button>
</form>
<p className="text-sm text-muted-foreground">{t("recovery.others")}</p>
</div>
);
}
+54
View File
@@ -0,0 +1,54 @@
"use client";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ErrorNotice } from "@/components/ui/notice";
import { register, type ErrorKey } from "./passkey";
export function SetupForm() {
const t = useTranslations("auth");
const router = useRouter();
const [error, setError] = useState<ErrorKey | null>(null);
const [busy, setBusy] = useState(false);
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
const form = new FormData(event.currentTarget);
setBusy(true);
setError(null);
const result = await register(
"/api/auth/setup/options",
{ code: form.get("code"), name: form.get("name"), household: form.get("household") },
"/api/auth/setup/verify",
);
setBusy(false);
if (result) setError(result);
else router.replace("/");
}
return (
<form onSubmit={onSubmit} className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
<Label htmlFor="code">{t("setup.code")}</Label>
<Input id="code" name="code" required autoComplete="one-time-code" autoCapitalize="characters" spellCheck={false} placeholder="XXXX-XXXX-XXXX-XXXX" />
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="name">{t("setup.name")}</Label>
<Input id="name" name="name" required maxLength={60} autoComplete="given-name" />
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="household">{t("setup.household")}</Label>
<Input id="household" name="household" required maxLength={80} placeholder={t("setup.householdPlaceholder")} />
</div>
{error ? <ErrorNotice>{t(`errors.${error}`)}</ErrorNotice> : null}
<Button type="submit" size="lg" disabled={busy}>
{busy ? t("working") : t("setup.submit")}
</Button>
<p className="text-sm text-muted-foreground">{t("setup.passkeyHint")}</p>
</form>
);
}
+52
View File
@@ -0,0 +1,52 @@
"use client";
import { LogOut } from "lucide-react";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { Button } from "@/components/ui/button";
import { LOCALES, type Locale } from "@/lib/locale";
const NAMES: Record<Locale, string> = { de: "Deutsch", en: "English", fr: "Français", es: "Español" };
export function LanguageSelect({ current }: { current: Locale }) {
const t = useTranslations("more");
const router = useRouter();
return (
<select
aria-label={t("language")}
className="min-h-11 rounded-xl border border-border bg-card px-4 text-base"
defaultValue={current}
onChange={async (event) => {
await fetch("/api/me/locale", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ locale: event.target.value }),
});
router.refresh();
}}
>
{LOCALES.map((l) => (
<option key={l} value={l}>
{NAMES[l]}
</option>
))}
</select>
);
}
export function SignOutButton() {
const t = useTranslations("more");
const router = useRouter();
return (
<Button
variant="outline"
onClick={async () => {
await fetch("/api/auth/logout", { method: "POST" });
router.replace("/anmelden");
}}
>
<LogOut aria-hidden />
{t("signOut")}
</Button>
);
}
+110
View File
@@ -0,0 +1,110 @@
"use client";
import { Check, Copy, Share2 } from "lucide-react";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { ErrorNotice } from "@/components/ui/notice";
type Created = { url: string; days: number };
async function create(body: object): Promise<Created | string> {
const res = await fetch("/api/household/invitations", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
const data = await res.json().catch(() => ({}));
return res.ok ? (data as Created) : String(data.error ?? "unknown");
}
function LinkResult({ created }: { created: Created }) {
const t = useTranslations("more");
const [copied, setCopied] = useState(false);
const canShare = typeof navigator !== "undefined" && "share" in navigator;
return (
<div className="flex flex-col gap-2 rounded-xl border border-border bg-muted p-3">
<p className="text-sm">{t("linkReady", { days: created.days })}</p>
<Input readOnly value={created.url} onFocus={(e) => e.currentTarget.select()} aria-label="Link" />
<div className="flex gap-2">
<Button
type="button"
variant="outline"
onClick={async () => {
await navigator.clipboard.writeText(created.url);
setCopied(true);
}}
>
{copied ? <Check aria-hidden /> : <Copy aria-hidden />}
{copied ? t("copied") : t("copy")}
</Button>
{canShare ? (
<Button type="button" variant="outline" onClick={() => navigator.share({ url: created.url }).catch(() => undefined)}>
<Share2 aria-hidden />
{t("share")}
</Button>
) : null}
</div>
</div>
);
}
export function InvitePerson() {
const t = useTranslations("more");
const te = useTranslations("auth.errors");
const [created, setCreated] = useState<Created | null>(null);
const [error, setError] = useState<string | null>(null);
return (
<form
className="flex flex-col gap-3"
onSubmit={async (event) => {
event.preventDefault();
const name = new FormData(event.currentTarget).get("name");
const result = await create({ kind: "person", name });
if (typeof result === "string") setError(result);
else {
setError(null);
setCreated(result);
}
}}
>
<div className="flex flex-col gap-2">
<Label htmlFor="invite-name">{t("inviteName")}</Label>
<Input id="invite-name" name="name" required maxLength={60} />
</div>
{error ? <ErrorNotice>{te.has(error) ? te(error) : te("unknown")}</ErrorNotice> : null}
<Button type="submit" variant="secondary">{t("inviteSubmit")}</Button>
{created ? <LinkResult created={created} /> : null}
</form>
);
}
export function AddDevice() {
const t = useTranslations("more");
const te = useTranslations("auth.errors");
const [created, setCreated] = useState<Created | null>(null);
const [error, setError] = useState<string | null>(null);
return (
<div className="flex flex-col gap-3">
<p className="text-sm text-muted-foreground">{t("addDeviceText")}</p>
{error ? <ErrorNotice>{te.has(error) ? te(error) : te("unknown")}</ErrorNotice> : null}
<Button
type="button"
variant="secondary"
onClick={async () => {
const result = await create({ kind: "device" });
if (typeof result === "string") setError(result);
else {
setError(null);
setCreated(result);
}
}}
>
{t("inviteSubmit")}
</Button>
{created ? <LinkResult created={created} /> : null}
</div>
);
}
+43
View File
@@ -0,0 +1,43 @@
"use client";
import { useRouter } from "next/navigation";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { Button } from "@/components/ui/button";
// Entfernen mit zweitem Tipp statt Dialog: Der erste Tipp fragt im Knopf
// selbst nach, der zweite entfernt.
export function RemoveButton({ url, id }: { url: string; id: string }) {
const t = useTranslations("more");
const te = useTranslations("auth.errors");
const router = useRouter();
const [armed, setArmed] = useState(false);
const [error, setError] = useState<string | null>(null);
return (
<span className="flex flex-col items-end gap-1">
<Button
type="button"
variant={armed ? "default" : "ghost"}
className="min-h-11 px-3 text-sm"
onBlur={() => setArmed(false)}
onClick={async () => {
if (!armed) return setArmed(true);
const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ id }) });
if (res.ok) router.refresh();
else {
const data = await res.json().catch(() => ({}));
setError(te.has(data.error) ? te(data.error) : te("unknown"));
setArmed(false);
}
}}
>
{armed ? t("confirmRemove") : t("remove")}
</Button>
{error ? (
<span role="alert" className="text-xs">
{error}
</span>
) : null}
</span>
);
}
+17
View File
@@ -0,0 +1,17 @@
import * as React from "react";
import { cn } from "@/lib/utils";
// shadcn/ui Input, 44 px hoch, Schrift 16 px (iOS zoomt sonst beim Tippen).
export const Input = React.forwardRef<HTMLInputElement, React.InputHTMLAttributes<HTMLInputElement>>(
({ className, ...props }, ref) => (
<input
ref={ref}
className={cn(
"flex min-h-11 w-full rounded-xl border border-border bg-card px-4 py-2 text-base text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50",
className,
)}
{...props}
/>
),
);
Input.displayName = "Input";
+6
View File
@@ -0,0 +1,6 @@
import * as React from "react";
import { cn } from "@/lib/utils";
export function Label({ className, ...props }: React.LabelHTMLAttributes<HTMLLabelElement>) {
return <label className={cn("text-sm font-medium", className)} {...props} />;
}
+12
View File
@@ -0,0 +1,12 @@
import { CircleAlert } from "lucide-react";
import { cn } from "@/lib/utils";
// Ein Fehler hat immer ein Zeichen und einen Satz — Farbe allein trägt nichts.
export function ErrorNotice({ children, className }: { children: React.ReactNode; className?: string }) {
return (
<p role="alert" className={cn("flex items-start gap-2 rounded-xl border border-primary/40 bg-primary/10 px-4 py-3 text-sm", className)}>
<CircleAlert aria-hidden className="mt-0.5 size-4 shrink-0 text-primary" />
<span>{children}</span>
</p>
);
}