Skip to content

feat: staff mode (sign-in + allow-list; no lead, cap exempt; ships inert) [rebased #160] - #162

Merged
razel-hash merged 5 commits into
mainfrom
lane/aeo-staff-mode-r2
Nov 10, 2026
Merged

razel-hash merged 5 commits into
mainfrom
lane/aeo-staff-mode-r2

Conversation

@razel-hash

Copy link
Copy Markdown
Collaborator

What

TDD task AEO-T-013 / FR-014, staff mode. Nothing changes until AEO_STAFF_EMAILS is set; it is unset on production.

  • The check (src/lib/staff.ts): a caller counts as staff only when all three hold:

    • its Authorization: Bearer token verifies with Supabase (server-side, using the service client);
    • the account's email is confirmed;
    • the email is on AEO_STAFF_EMAILS.

    Anything else counts as public: no list, no token, a bad header, an unconfirmed email, or an auth error.

  • Unlock: a staff member gets the unlock cookie without the name/email form. No lead row is written and HubSpot gets no call (AC-020). The per-IP limiter and the audit-ready check still apply.

  • Start: staff skip staff_only and the daily cap (AC-019). Pause, config and preview rules still apply. Staff rows get requested_by = 'staff'. Once staff are configured, the daily count only includes rows where requested_by is null.

  • Browser:

    • GET /api/staff returns only {staff: boolean}.
    • The header shows a Staff badge after the server confirms.
    • The report asks /api/staff first, then unlocks for staff only, so a signed-in non-staff browser uses none of the unlock limit.
    • The audit form sends the sign-in token.
  • supabase/drafts/008_*: adds the nullable requested_by column. It is not applied.

Order before anyone sets AEO_STAFF_EMAILS (the owner's steps):

  1. Apply draft 008.
  2. In Supabase, turn sign-ups off and keep "Confirm email" on.
  3. Create each staff account.
  4. Then set AEO_STAFF_EMAILS.

Rebased onto main after #151 and #154 (replaces #160). The staff token check now runs after the per-IP limiter, so a caller over their limit costs no auth call. The custom-prompts gate from #151 also leaves staff audits out of the count.

Pipeline: /tdd (staff.test, the unlock staff cases, the gate staff case and the start staff cases each failed first; the confirmed-email rule was also checked by removing it, and 1 test fails without it) → code-reviewer subagent with a security lens

Risk

  • Nothing changes in production while AEO_STAFF_EMAILS is unset. The count query and the insert are the same as today.
  • If the variable is set before draft 008 is applied, starting an audit fails (the column is missing). The draft and this PR both say so.
  • A junk bearer token costs one Supabase auth call, and only once a staff list is set.
  • Rollback: unset AEO_STAFF_EMAILS, or revert the PR.

Code review: the code-reviewer subagent rated it "safe with notes". Its High finding was that an unconfirmed email could pass as staff once the list is set; that is fixed and has a test. Its Low finding was that the report's auto-check used up unlock attempts; that is fixed with the /api/staff check first. Left as is: /api/staff has no rate limit of its own. It answers only yes or no, and it does nothing until a list is set.

Checks: npx vitest run passed 228/228 tests in 20 files, on the rebased branch. npx tsc --noEmit is clean.

🤖 Generated with Claude Code

razel-hash and others added 5 commits November 10, 2026 21:20
… migration draft

Not wired into routes yet. Unset AEO_STAFF_EMAILS means nobody is staff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…adge, token sent on audit start

- unlock: an allow-listed staff sign-in gets the unlock cookie without name/email;
  no lead row, no HubSpot sync
- report: a signed-in browser asks once; the server decides; public visitors unchanged
- header: Staff badge after the server confirms (GET /api/staff, yes/no only)
- audit form sends the sign-in token, for the run gate's staff rule

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rked and left out of the count

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ore unlocking

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…count too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
campaign-creators-aeo-auditor Ready Ready Preview Nov 10, 2026 1:23pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 80f0de4c Deployed Nov 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant