mirror of
https://github.com/better-auth/better-auth.git
synced 2026-08-03 08:49:26 -05:00
fix(stripe): onCustomerCreate should be called even if update user isn't returned (#4716)
This commit is contained in:
@@ -125,6 +125,7 @@ export const createInternalAdapter = (
|
||||
undefined,
|
||||
context,
|
||||
);
|
||||
|
||||
return createdUser as T & User;
|
||||
},
|
||||
createAccount: async <T extends Record<string, any>>(
|
||||
|
||||
@@ -1242,21 +1242,19 @@ export const stripe = <O extends StripeOptions>(options: O) => {
|
||||
userId: user.id,
|
||||
},
|
||||
});
|
||||
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?.(
|
||||
{
|
||||
stripeCustomer,
|
||||
user,
|
||||
await ctx.context.internalAdapter.updateUser(user.id, {
|
||||
stripeCustomerId: stripeCustomer.id,
|
||||
});
|
||||
await options.onCustomerCreate?.(
|
||||
{
|
||||
stripeCustomer,
|
||||
user: {
|
||||
...user,
|
||||
stripeCustomerId: stripeCustomer.id,
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
},
|
||||
ctx,
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -188,7 +188,7 @@ export interface StripeOptions {
|
||||
onCustomerCreate?: (
|
||||
data: {
|
||||
stripeCustomer: Stripe.Customer;
|
||||
user: User;
|
||||
user: User & { stripeCustomerId: string };
|
||||
},
|
||||
ctx: GenericEndpointContext,
|
||||
) => Promise<void>;
|
||||
|
||||
Reference in New Issue
Block a user