Files
vitareba/app/api
g-butandClaude Opus 4.7 ca12b1de21 fix(account): close check-then-insert race in registration
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>
2026-04-26 10:45:02 +02:00
..