fix(12): WR-01 delete orphaned user row on re-select 503 path in /credential

After $returningId() insert, if the re-select returns null the handler
returned 503 without deleting the just-inserted user row, leaving an
unclaimed admin row with no credential. Delete before returning 503 to
mirror the cleanup already present in the catch block.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lucas Berger
2026-06-15 16:14:39 -04:00
co-authored by Claude Sonnet 4.6
parent 066b69f2be
commit 3bc38bf1a6
+3
View File
@@ -275,6 +275,9 @@ setupRouter.post('/credential', zValidator('json', credentialSchema, noEchoHook)
.limit(1);
if (!localUser) {
// Clean up the just-inserted user row to avoid an orphaned unclaimed admin
// (WR-01: the catch block below does not cover this early-return path).
await db.delete(users).where(eq(users.id, inserted.id));
return c.json({ error: 'Service unavailable' }, 503);
}