Phase 12: share an event with co-hosts
The owner shares an event by email; a co-host gets full access inside it but can't delete it or change who it's shared with. Shares are keyed by email so an admin can be added before their first login, and RLS (not the UI) is what enforces the owner-only parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { CohostsEditor } from "@/components/admin/cohosts-editor";
|
||||
import { EventDetailsForm } from "@/components/admin/event-details-form";
|
||||
import { GamesEditor } from "@/components/admin/games-editor";
|
||||
import { SharePanel } from "@/components/admin/share-panel";
|
||||
@@ -11,12 +12,16 @@ import { loadEventSetup } from "@/lib/queries/event";
|
||||
import { idSchema } from "@/lib/tokens";
|
||||
|
||||
export default async function EventSetupPage(props: PageProps<"/admin/events/[eventId]">) {
|
||||
const { supabase } = await requireAdmin();
|
||||
const { supabase, userId } = await requireAdmin();
|
||||
const { eventId } = await props.params;
|
||||
if (!idSchema.safeParse(eventId).success) notFound();
|
||||
|
||||
const setup = await loadEventSetup(supabase, eventId);
|
||||
const [setup, cohosts] = await Promise.all([
|
||||
loadEventSetup(supabase, eventId),
|
||||
supabase.from("event_cohosts").select("id, email").eq("event_id", eventId).order("created_at"),
|
||||
]);
|
||||
if (!setup) notFound();
|
||||
if (cohosts.error) throw new Error(`Could not load the co-hosts: ${cohosts.error.message}`);
|
||||
const { event, teams, games } = setup;
|
||||
|
||||
return (
|
||||
@@ -65,6 +70,11 @@ export default async function EventSetupPage(props: PageProps<"/admin/events/[ev
|
||||
<h2 className="text-xl font-bold">Share links</h2>
|
||||
<SharePanel scoreboardToken={event.scoreboard_token} teams={teams} games={games} />
|
||||
</section>
|
||||
|
||||
<section className="rounded-lg border border-ink/15 bg-white p-4">
|
||||
<h2 className="text-xl font-bold">Co-hosts</h2>
|
||||
<CohostsEditor eventId={event.id} cohosts={cohosts.data} isOwner={event.owner_id === userId} />
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user