Stripe plugin create a new customer on subscription.upgrade click.
I have 2 different buttons to subscription.upgrade in my app. After user is registered customer is created in stripe according to createCustomerOnSignUp: true, in plugin config. But when I navigate to one of my 'Subscribe' buttons and click on it -> subscription.upgrade just creates new user in stripe instead of triggering checkout session:
CustomerId also assigned properly to user initially after signup.
Does anyone know why this happens and how to fix it ?
7 Replies
I experience the same behavior. Have you found out why this is happening yet?
Still have no idea. No response. I just implemented Stripe separately.
@bekacru Can you help us out with this?
I created an issue on this btw, because I am still experiencing it and it's quite annoying.
https://github.com/better-auth/better-auth/issues/2440
BUT! I think I know why this is happening!
@Glen Kurio Are you using a secondary storage for your sessions, like redis or something?
Because I do have a secondary storage and I noticed that after a user registers, the customer gets created, but then the user in the session is not updated with the new customerId only the main db has this new entry. So when that user with the misaligned session tries to activate a subscription, their customerId is
null
, which is probably why a new customer is created, either by stripe or BA (that I dont know yet).
@bekacru Is there something special we have to do to keep the user data in the session in the secondary storage in sync with the user data in DB after a registration (maybe not only after a registration, because what if createCustomerOnSignUp
is set to false
?)? Are we responsible to add a hook for this or something?
Perhaps it's worth noting that I do the registration server-side.GitHub
stripe subscription.upgrade creates a new customer every time · Is...
Is this suited for github? Yes, this is suited for github To Reproduce Setup BA with the stripe plugin Make sure you add createCustomerOnSignUp: true to the stripe plugin config Locally forward str...
@bekacru @Ping Sorry if I'm pinging you guys too often, but this issue has been around for a long time and it's quite annoying 🙈 Can you please help me out here? I'm too unfamiliar with BA's codebase.
Could this issue maybe be fixed by calling
await ctx.context.internalAdapter.update
instead of await ctx.context.adapter.update
in the BA "/subscription/upgrade"
endpoint? At both lines packages/stripe/src/index.ts:242
& packages/stripe/src/index.ts:982
. According to the docs the internalAdapter
also takes care of updating the user data in the secondary storage, wheras the adapter
simply updates the DB. Could this be the issue?
I tried to find a workaround with a BA hook, to manually update the user in my secondary storage after a customer is created, but I somehow can't get the current session token. Both the session
and newSession
are null
in the after or before hook
Also when I try to update the user myself via
It won't do anything to the secondary storage.will get it fixed for 1.2.9 - tonight or tmrw
I just upgraded and tested it again. The bug is still there. The
stripeCustomerId
still remains null
in the secondary storage after signing in. 🙈
Just upgraded to 1.3.3
and cannot reproduce this anymore. WOOH! Good job team BA! 🥳
Actually @bekacru the underlying issue that the stripeCustomerId
in the secondary storage isn't updated after a signUp still remains. This leads to my user data in locals
(in SvelteKit) to be inconsistent with the data from the db.
I explained it a bit further in this thread here:
https://discord.com/channels/1288403910284935179/1363601316202680432/1380533147741192302
And a possible solution here:
https://discord.com/channels/1288403910284935179/1363601316202680432/1381170380495913001
What do you think @bekacru ?sorry for the late repsponse here. Opened a PR. This should fix it I think
https://github.com/better-auth/better-auth/pull/3635
GitHub
fix(stripe): update customer id should also trigger secondary stora...
Summary by cubic
Updating a user's Stripe customer ID now also updates the secondary storage to keep user data in sync.
Refactors
Removed the old Customer type and related code.
Switched ...