Open jbwashington opened 11 months ago
@jbwashington is attempting to deploy a commit to the Tier Team on Vercel.
A member of the Team first needs to authorize it.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
tier-vercel-openai | ❌ Failed (Inspect) | Nov 17, 2023 1:26pm |
… ensure only one subscription per user
Description 📣
i was having this problem where new users would be subscribed 2-3x on Stripe upon logging in and couldn’t figure out why.
The reason why is this block of code on line 23 from
auth.ts
inauthOptions
of the Metered Billing example:The duplicate subscriptions would cause some weird bugs, primarily
tier.report()
reporting to the wrong subscription andtier.limit()
not displaying the correct usage, etc. the correct place for this try/catch block inauthOptions
is thecreateUser
trigger in events:This way, it only fires on the first time the org is not found, and not every time
getSession
runs.Type ✨
Tests 🛠️
Before the code change, 3 subscriptions were created, presumably because
getSession
was fired 3 times in the auth process before the response fromprisma.user.create()
returns, triggering a creation for each session call. Also,tier.report()
would not increment on the client side because the wrong subscription was tied to the user. after clearing Stripe test data and db, subscription is created only once in Stripe andtier.can()
/tier.report()
works as expected.