mirror of
https://github.com/bitbaum/vitareba.git
synced 2026-12-05 06:48:03 +01:00
POST /api/account looked up the email, then inserted — two concurrent
requests with the same new email both passed the findFirst, then one
won the unique-constraint race and the other returned a generic 500
"Registration failed". The user behind the losing request couldn't
tell their email was just registered (e.g. by themselves on another
device) vs a real backend issue.
Kept the up-front check (so we avoid the bcrypt cost in the common
case where the email is already known to exist), but hardened the
insert with onConflictDoNothing({ target: users.email }) and check
inserted.length === 0 — the racing loser now surfaces as the same 409
the up-front check returns, with the same { email: ["Email already
registered"] } error body the form already handles.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>