diff --git a/server/src/routes/webhook.js b/server/src/routes/webhook.js index 4c90874..0fc4952 100644 --- a/server/src/routes/webhook.js +++ b/server/src/routes/webhook.js @@ -55,6 +55,11 @@ router.post('/stripe', async (req, res) => { try { const email = await getCustomerEmail(subscription.customer); if (email) { + // Skip non-active created events to avoid overwriting premium with incomplete status + if (!premium && event.type === 'customer.subscription.created') { + console.log(`[webhook] Subscription created: ${email} -> ${subscription.status} (skipped cache update)`); + break; + } storage.setSubscriptionStatus(email, premium, subscription.customer); console.log(`[webhook] Subscription ${action}: ${email} -> ${premium ? 'premium' : 'free'}`); diff --git a/server/src/storage/index.js b/server/src/storage/index.js index 646a30e..8777f44 100644 --- a/server/src/storage/index.js +++ b/server/src/storage/index.js @@ -78,7 +78,10 @@ function setSubscriptionStatus(email, premium, customerId) { function getSubscriptionStatus(email) { const data = readSubscriptionFile(); - return data[email.toLowerCase()] || null; + const entry = data[email.toLowerCase()]; + if (!entry) return null; + if (Date.now() - entry.updatedAt > 10000) return null; + return entry; }