fix(auth): await welcome email inline so it lands before verify on signup #304
No reviewers
Labels
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
psa-systems/bunyip!304
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/BUNYIP-296-welcome-before-verify"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Both mails around registration are dispatched via
tokio::spawntoday, so their SMTP submission order depends on scheduler timing.registerspawnssend_account_createdand returns 201; bunyip-web redirects to /onboarding; the onboarding GET auto-firesPOST /v1/users/me/email/verify, which spawnssend_email_verify. Both spawned tasks race, and the verify request reliably lands within ~50-200 ms of the register response - well inside the window a slow welcome mail can lose to. The user then sees "Verify your email" before "Welcome to Bunyip", which reads as a broken sequence for the very first two mails they will ever get from us.Move the welcome dispatch to an inline
.awaitinsideregister. The send stays best-effort (a mail failure logs and continues, because register has already committed the row and dashboard access does not depend on a delivered welcome), but the response only returns after the welcome is on the SMTP wire. The onboarding page's auto-verify (which runs in the browser only AFTER it has received the register response and navigated) cannot fire earlier than the welcome by construction.Cost: the register response is delayed by SMTP submission latency (typically 50-500 ms on a warm connection). Acceptable because the perceived latency of the register flow is dominated by the redirect to /onboarding and its render, not by the 201, and the SMTP timeout in
EmailServicebounds worst-case hang.Same inline-await applied to the
MagicLinkResult::Successnew-user branch for stylistic uniformity. Magic-link signup verifies the email as part of the flow itself, so no verify message follows and the ordering-race concern does not apply there; the change is cosmetic parity between the two signup paths, not a correctness fix at that call site.Out of scope:
POST /v1/users/me/email/verifystilltokio::spawns its send. Templates + copy are BUNYIP-288's; the onboarding auto-send +VERIFY_SENT_COOKIEcookie gate are unchanged.#BUNYIP-296
31384bdae4f9ca921df1