fix(auth): compute accurate retry_after for email resend limiters #311
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/BUNYIP-313-accurate-retry-after"
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?
The email-verification and email-change resend limiters both returned a hardcoded retry_after of 3600 once the 3-per-hour threshold was hit, so a user who made their 3 requests 55 minutes ago was still told to wait a full hour. That value flows through to the Retry-After header and the details.retry_after body field, so it must be truthful.
Add MIN(created_at) repository queries (oldest_recent_email_verification_token, oldest_recent_email_change_request) that return the oldest in-window request time, and a pure resend_retry_after_secs(oldest, now) helper that reports the real seconds until the window frees up (oldest + window - now), clamped to >= 1. The window and threshold are now the named constants RESEND_LIMIT_WINDOW_SECS and RESEND_LIMIT_MAX (single source of truth, pub so the admin read path in BUNYIP-315 can reuse them). Throttling still triggers on the 4th request within an hour; only the reported time changed.
#BUNYIP-313