fix(keys): add DB fallback to updateEmailByCustomer, updateKeyEmail, and recover route (BUG-108, BUG-109, BUG-110)
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 13m8s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 13m8s
- updateEmailByCustomer: DB fallback when stripe_customer_id not in cache - updateKeyEmail: DB fallback when key not in cache - POST /v1/recover: DB fallback when email not in cache (was only on verify) - 6 TDD tests added (keys-email-update.test.ts, recover-initial-db-fallback.test.ts) - 547 tests total, all passing
This commit is contained in:
parent
424a16ed8a
commit
d376d586fe
4 changed files with 286 additions and 4 deletions
|
|
@ -69,6 +69,18 @@ router.post("/", recoverLimiter, async (req: Request, res: Response) => {
|
|||
const userKey = keys.find(k => k.email === cleanEmail);
|
||||
|
||||
if (!userKey) {
|
||||
// DB fallback: cache may be stale in multi-replica setups
|
||||
const dbResult = await queryWithRetry(
|
||||
"SELECT key FROM api_keys WHERE email = $1 LIMIT 1",
|
||||
[cleanEmail]
|
||||
);
|
||||
if (dbResult.rows.length > 0) {
|
||||
const pending = await createPendingVerification(cleanEmail);
|
||||
sendVerificationEmail(cleanEmail, pending.code).catch(err => {
|
||||
logger.error({ err, email: cleanEmail }, "Failed to send recovery email");
|
||||
});
|
||||
logger.info({ email: cleanEmail }, "recover: cache miss, sent recovery via DB fallback");
|
||||
}
|
||||
res.json({ status: "recovery_sent", message: "If an account exists for this email, a verification code has been sent." });
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue