mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-23 23:52:05 -05:00
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:
5
.changeset/huge-needles-smell.md
Normal file
5
.changeset/huge-needles-smell.md
Normal 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
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -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"> {}
|
||||
|
||||
Reference in New Issue
Block a user