Add household seeding & session (task 07)

- scripts/seed.ts: idempotent pnpm db:seed inserts "Home" household if none exists (powered by tsx)
- signIn callback: first member of household gets owner role, subsequent users get member
- src/lib/session.ts: getCurrentSession() returns { user, household, role }, throws if unauthenticated or unmembered
- /settings/household: member list for all roles; rename form gated to owner only (server action also enforces)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ginnoir
2026-05-06 02:42:48 -05:00
co-authored by Claude Sonnet 4.6
parent 5da472d6ff
commit 6710c8b231
9 changed files with 152 additions and 4 deletions
+22
View File
@@ -0,0 +1,22 @@
"use server";
import { eq } from "drizzle-orm";
import { revalidatePath } from "next/cache";
import { db } from "@/lib/db";
import { getCurrentSession } from "@/lib/session";
import { households } from "@/modules/_core/schema";
export async function renameHousehold(formData: FormData) {
const { household, role } = await getCurrentSession();
if (role !== "owner") throw new Error("Forbidden");
const name = formData.get("name");
if (typeof name !== "string" || !name.trim()) throw new Error("Invalid name");
await db
.update(households)
.set({ name: name.trim() })
.where(eq(households.id, household.id));
revalidatePath("/settings/household");
}