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:
@@ -8,7 +8,7 @@ Next.js (App Router) on Vercel · Supabase (Postgres + Auth + Realtime Broadcast
|
||||
|---|---|---|
|
||||
| `/login` | admin | Supabase magic link |
|
||||
| `/admin` | admin | Events list |
|
||||
| `/admin/events/[eventId]` | admin | Setup: teams, games, criteria, judges, share links |
|
||||
| `/admin/events/[eventId]` | admin | Setup: teams, games, criteria, judges, share links, co-hosts |
|
||||
| `/admin/events/[eventId]/live` | admin | Control room |
|
||||
| `/s/[scoreboardToken]` | public | Scoreboard |
|
||||
| `/j/[judgeToken]` | judge | Personal judge page |
|
||||
@@ -29,7 +29,8 @@ Admin mutations = server actions. `src/proxy.ts` (Next.js 16's name for middlewa
|
||||
- `admin.ts` — service role, **server-only** (`import 'server-only'`). Used by public/judge route handlers after token validation.
|
||||
|
||||
## Security model
|
||||
- RLS ON for every table. Policies only for the authenticated event owner. Anon role has no policies → no direct table access.
|
||||
- RLS ON for every table. Policies only for the authenticated event owner and the co-hosts the owner shared it with. Anon role has no policies → no direct table access.
|
||||
- Co-hosts are rows in `event_cohosts`, matched on the email in the login token. They get the same access as the owner inside the event; only the owner can delete the event or change its co-hosts (enforced by RLS — the UI just hides those buttons). Sharing is refused for an email that isn't in `ADMIN_EMAILS`, since that person couldn't log in.
|
||||
- Public/judge access = token in URL → route handler validates with zod → service-role query scoped by that token.
|
||||
- Judge write checks: judge not revoked, game not locked/done, criterion belongs to judge's game, team belongs to the game's event, value within min/max and on step. (DB trigger also enforces range.)
|
||||
- Scoreboard API checks `scoreboard_visibility` and strips scores when `hidden`; returns `frozen_snapshot` when `frozen`.
|
||||
|
||||
+9
-1
@@ -81,5 +81,13 @@ show who was first within a second, and "Clear buzzers" resets both phones.
|
||||
**Done when:** team A buzzes then team B; "Wrong" hands the turn to B; "Got it" gives B one point
|
||||
in the scoring grid and on the scoreboard; "Undo" takes it back; "Next question" resets the phones.
|
||||
|
||||
## Phase 12 — Co-hosts
|
||||
- Apply `supabase/migrations/0005_cohosts.sql`, then `npm run gen:types` and `npm run check:rls`.
|
||||
- `event_cohosts` table; RLS widened from owner to owner-or-co-host, with delete and sharing owner-only.
|
||||
- "Co-hosts" section on the setup page (`addCohost` / `removeCohost` server actions); "Shared with you" in the events list.
|
||||
**Done when:** admin A shares an event with admin B's email; B sees it in their list, can edit it and
|
||||
run the control room alongside A, but has no Delete button and can't change the co-hosts; removing B
|
||||
makes the event disappear from B's list.
|
||||
|
||||
## Stretch (only if asked)
|
||||
Participants within teams · co-host admins · CSV export of results.
|
||||
Participants within teams · CSV export of results.
|
||||
|
||||
+3
-1
@@ -1,6 +1,6 @@
|
||||
# Data model
|
||||
|
||||
Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `0003_buzzer.sql`, `0004_buzz_result.sql`).
|
||||
Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `0003_buzzer.sql`, `0004_buzz_result.sql`, `0005_cohosts.sql`).
|
||||
|
||||
| Table | Purpose | Key columns |
|
||||
|---|---|---|
|
||||
@@ -12,6 +12,7 @@ Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `000
|
||||
| `scores` | One value per (team, criterion, judge) | `judge_id` NULL = admin score (direct mode or override) |
|
||||
| `adjustments` | Bonus/penalty | `points` (+/-), `reason`, optional `game_id` |
|
||||
| `buzzes` | Who buzzed for the current question | `game_id`, `team_id`, `buzzed_at`, `result` (correct/wrong/NULL) |
|
||||
| `event_cohosts` | Admins an event is shared with | `event_id`, `email` (lower case), unique together |
|
||||
|
||||
## Notes
|
||||
- `scores` unique on `(team_id, criterion_id, judge_id)` with `NULLS NOT DISTINCT`, so there's exactly one admin row per team+criterion → clean upserts.
|
||||
@@ -20,4 +21,5 @@ Full SQL in `supabase/migrations/` (`0001_init.sql`, then `0002_timer.sql`, `000
|
||||
- Timer (`0002_timer.sql`): running = `timer_ends_at` set; paused = `timer_remaining_ms` set; reset = both null (full `timer_duration_ms`).
|
||||
- Buzzers (`0003_buzzer.sql`): `buzzes` is unique on `(game_id, team_id)` — one buzz per team per question; `buzzed_at` defaults to `clock_timestamp()` and decides the order. Clearing the buzzers deletes the game's rows. A trigger checks the team is in the game's event. `teams.buzzer_token` is a 128-bit token like the others; duplicating an event gives the copied teams new ones.
|
||||
- Buzzer answers (`0004_buzz_result.sql`): `buzzes.result` is the host's mark. The team answering is the earliest buzz with `result IS NULL`, unless some buzz is `correct` (question decided). The point for a correct answer is not stored on the buzz: it is +1 on the admin's `scores` row for the game's first criterion.
|
||||
- Co-hosts (`0005_cohosts.sql`): a share is keyed by email, not user id, so an admin can be added before they have ever logged in. RLS matches it against the email in the login token. `is_event_admin(event)` = owner or co-host and guards every table inside an event; deleting the event and editing `event_cohosts` stay owner-only. A trigger stops `events.owner_id` from changing.
|
||||
- `frozen_snapshot` holds the `ScoreboardPayload` captured at freeze time.
|
||||
|
||||
+8
-2
@@ -7,7 +7,7 @@ live scoreboard, and judges score from their phones via links. Versatile enough
|
||||
## 2. Roles
|
||||
| Role | Access | How they get in |
|
||||
|---|---|---|
|
||||
| **Admin** | Everything | Logs in (magic link). Email must be in `ADMIN_EMAILS`. |
|
||||
| **Admin** | Everything in the events they own or co-host | Logs in (magic link). Email must be in `ADMIN_EMAILS`. |
|
||||
| **Scoreboard viewer** | Read-only scoreboard for ONE event | Public link `/s/{scoreboardToken}` |
|
||||
| **Judge** | Score ONE game | Personal link `/j/{judgeToken}` OR open game link `/jo/{openToken}` (enters name first) |
|
||||
| **Team** | Buzz in for ONE team | Team buzzer link `/b/{buzzerToken}`, one per team for the whole night |
|
||||
@@ -46,6 +46,12 @@ live scoreboard, and judges score from their phones via links. Versatile enough
|
||||
- Revoke a judge (link stops working, their scores excluded).
|
||||
- Share panel: scoreboard link + QR, all judge links per game, and one buzzer link + QR per team
|
||||
(shown once any game uses buzzers).
|
||||
- Co-hosts: the admin who created an event (its owner) shares it with other admins by email.
|
||||
- The email must already be in `ADMIN_EMAILS`; it can be added before that admin's first login.
|
||||
- A co-host sees the event in their list ("Shared with you") and can do everything in it —
|
||||
setup, control room, scores — except delete it or change who it is shared with.
|
||||
- The owner can remove a co-host at any time. Duplicating a shared event gives the co-host
|
||||
their own copy, which they own.
|
||||
|
||||
### 4.2 Admin — Control room (`/admin/events/[id]/live`)
|
||||
This is the screen used during the night. Must be fast and hard to mess up.
|
||||
@@ -152,7 +158,7 @@ For "first to answer" games. A game opts in with the "Teams buzz in" checkbox.
|
||||
|
||||
## 6. Out of scope (v1)
|
||||
- Individual contestants within teams (stretch: `participants` per team).
|
||||
- Multiple admins / co-hosts (stretch).
|
||||
- Transferring an event to another owner, and read-only co-hosts.
|
||||
- Per-game timers (stretch). The event countdown timer is in 4.5; team buzzers are in 4.7.
|
||||
- Buzzers for individual contestants, a configurable points value per correct answer, and
|
||||
penalties for a wrong answer (use the bonus/penalty panel).
|
||||
|
||||
Reference in New Issue
Block a user