fix(stripe): update customer id should also trigger secondary storage update (#3635)

* fix: update customer id should also update secondary storage

* chore: add changeset
This commit is contained in:
Bereket Engida
2025-07-26 12:07:55 -07:00
committed by GitHub
parent 8fdcf54a7b
commit a536de91c2
3 changed files with 10 additions and 27 deletions

View File

@@ -0,0 +1,5 @@
---
"@better-auth/stripe": patch
---
Fix an issue where updating Stripe customer ID wasn't properly syncing with secondary storage during user creation

View File

@@ -18,7 +18,6 @@ import {
onSubscriptionUpdated,
} from "./hooks";
import type {
Customer,
InputSubscription,
StripeOptions,
StripePlan,
@@ -1123,26 +1122,15 @@ export const stripe = <O extends StripeOptions>(options: O) => {
userId: user.id,
},
});
const customer = await ctx.context.adapter.update<Customer>(
{
model: "user",
update: {
stripeCustomerId: stripeCustomer.id,
},
where: [
{
field: "id",
value: user.id,
},
],
},
);
if (!customer) {
const updatedUser =
await ctx.context.internalAdapter.updateUser(user.id, {
stripeCustomerId: stripeCustomer.id,
});
if (!updatedUser) {
logger.error("#BETTER_AUTH: Failed to create customer");
} else {
await options.onCustomerCreate?.(
{
customer,
stripeCustomer,
user,
},

View File

@@ -187,7 +187,6 @@ export interface StripeOptions {
*/
onCustomerCreate?: (
data: {
customer: Customer;
stripeCustomer: Stripe.Customer;
user: User;
},
@@ -330,13 +329,4 @@ export interface StripeOptions {
schema?: InferOptionSchema<typeof subscriptions & typeof user>;
}
export interface Customer {
id: string;
stripeCustomerId?: string;
userId: string;
createdAt: Date;
updatedAt: Date;
}
export interface InputSubscription extends Omit<Subscription, "id"> {}
export interface InputCustomer extends Omit<Customer, "id"> {}