Skip to content

fix: validate co-organizer invites and match emails case-insensitively - #218

Merged
TheCodeHeist-Coder merged 1 commit into
TheCodeHeist-Coder:mainfrom
Anshuu2004:fix/coorganizer-invite-validation
Oct 26, 2026
Merged

TheCodeHeist-Coder merged 1 commit into
TheCodeHeist-Coder:mainfrom
Anshuu2004:fix/coorganizer-invite-validation

Conversation

@Anshuu2004

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes the co-organizer invite flow so bad input gets a proper error instead of a 500, and the sidebar actually lists people.

Backend (inviteController.ts):

  • no email, a blank one, or an invalid one now gives 400
  • inviting yourself, someone already invited, or someone already an organizer gives 409 with its own message. I check inviteEmail as well as the user, because the @@unique([userId, quizId]) constraint doesn't catch repeat invites to an email that has no account yet (userId is null there)
  • emails are trimmed and lower cased when stored, and the match on accept ignores case, so old rows saved in mixed case still work
  • an organizer who opens a second invite link gets a 409 instead of a 500, and I delete the leftover pending row so it doesn't sit in the list
  • Prisma P2002 is caught as a fallback on both endpoints

Frontend (QuizBuilder.tsx):

  • the invite form shows the error text from the API instead of always "Failed to invite."
  • the sidebar was reading quiz.organizers but the API sends quizOrganizers, so it was always empty. Fixed, and it shows OWNER / ACCEPTED / PENDING
  • the quiz reloads after a successful invite so the pending one shows up

http-server had no tests so I added vitest the way ws-server has it, one small test file for the email check, and a test step in ci.yml. Same setup lines as my other PR for #211, so whichever merges first the other should apply cleanly.

co-organizers sidebar with owner, accepted, pending and the already an organizer message

Related issue

Closes #214

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactoring
  • Performance
  • Tests
  • Build / CI / deployment

Which services does this touch?

  • apps/frontend
  • apps/http-server
  • apps/ws-server
  • apps/genAI
  • packages/db (schema or Prisma changes)
  • Docker / CI

How did you test this?

  • pnpm --filter http-server run test: 14 pass
  • pnpm --filter frontend run test: 75 pass, 3 of them new (sidebar and the error message)
  • ran http-server on a throwaway Postgres with all migrations and hit the endpoints before and after. Before: no email 500, blank or invalid email 200, inviting yourself 200, inviting the same user twice 500, second invite link for an existing organizer 500, a Bob@Example.com account could not accept an invite sent to bob@example.com. After: 400 for missing, blank and invalid email, 409 for self invite, 409 "Already invited" (also for a different letter case and for an email with no account), 409 "Already an organizer", 409 on the second invite link, and the mixed case account accepts fine
  • ran the frontend with vite against that server and looked at the sidebar in a browser (screenshot above), one session only
  • I did not try docker compose up

Checklist

  • I ran pnpm run lint
  • I ran pnpm run check-types
  • I ran pnpm run build
  • The app still starts with docker-compose up
  • I updated documentation if this changes behaviour or setup
  • I did not commit any .env file, API key or other secret

pnpm run lint still fails in the frontend because of errors that were already on main (18, mostly no-explicit-any), my change adds none. check-types has no script for http-server or the frontend, so I also ran tsc on both and it passes. No schema change, no migration.

Invites now return 400 for a missing or invalid email and 409 for a
duplicate invite, an existing organizer or the owner inviting themselves,
instead of a 500 from the unique constraint. Emails are trimmed and lower
cased when stored and compared case-insensitively on accept. QuizBuilder
shows the server's error and reads quizOrganizers for the sidebar.
@TheCodeHeist-Coder
TheCodeHeist-Coder self-requested a review October 26, 2026 12:44
@TheCodeHeist-Coder
TheCodeHeist-Coder merged commit e174fa1 into TheCodeHeist-Coder:main Oct 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Co-organizer invites: inviting the same person twice, yourself, or with no email returns 500, and invited emails are matched case-sensitively

2 participants