[STRIPE] Make stripeCustomerId not optional #2713

Closed
opened 2026-03-13 10:14:55 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @pauksztello on GitHub (Jan 15, 2026).

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

Hello,

Is it possible to make stripeCustomerId non-optional when using createCustomerOnSignUp: true?

Currently, the generated schema does not apply .notNull() to the user’s stripeCustomerId field, and it is inferred as:

stripeCustomerId?: string | null | undefined;

Describe the solution you'd like

Make this field required when createCustomerOnSignUp: true is used, or provide an additional option to enforce this.

Describe alternatives you've considered

Currently, I have a wrapper around the getSession call that casts the wanted type.

Additional context

No response

Originally created by @pauksztello on GitHub (Jan 15, 2026). Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Hello, Is it possible to make stripeCustomerId non-optional when using `createCustomerOnSignUp: true`? Currently, the generated schema does not apply .notNull() to the user’s stripeCustomerId field, and it is inferred as: `stripeCustomerId?: string | null | undefined;` ### Describe the solution you'd like Make this field required when `createCustomerOnSignUp: true` is used, or provide an additional option to enforce this. ### Describe alternatives you've considered Currently, I have a wrapper around the getSession call that casts the wanted type. ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 10:14:55 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 15, 2026):

Thank you for your question regarding the stripeCustomerId field in Better Auth when using createCustomerOnSignUp: true. Currently, the stripeCustomerId is treated as optional in the generated schema, which can lead to issues if your implementation requires it to be mandatory.

There is a related open issue where the suggestion is to make this field required when createCustomerOnSignUp: true is set, or to provide an additional option to enforce this requirement. This issue is under discussion and not yet resolved [3].

If you would like to ensure that your specific needs are addressed, I recommend tagging @bekacru and @ping__ for more detailed guidance from the Better Auth team.

Is there anything else I can help you with regarding Better Auth?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Jan 15, 2026): Thank you for your question regarding the `stripeCustomerId` field in Better Auth when using `createCustomerOnSignUp: true`. Currently, the `stripeCustomerId` is treated as optional in the generated schema, which can lead to issues if your implementation requires it to be mandatory. There is a related open issue where the suggestion is to make this field required when `createCustomerOnSignUp: true` is set, or to provide an additional option to enforce this requirement. This issue is under discussion and not yet resolved [[3]](https://github.com/better-auth/better-auth/pull/7353). If you would like to ensure that your specific needs are addressed, I recommend tagging @bekacru and @ping__ for more detailed guidance from the Better Auth team. Is there anything else I can help you with regarding Better Auth? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@bytaesu commented on GitHub (Jan 15, 2026):

Hi @pauksztello,

Even if createCustomerOnSignUp is enabled, there can be a delay before the webhook result is received from Stripe. If stripeCustomerId is marked as required, the DB operation itself may fail.

Also, createCustomerOnSignUp can be toggled in some use cases, and changing the database schema every time doesn't seem appropriate.

Feel free to let me know if I’m missing something 🙏

@bytaesu commented on GitHub (Jan 15, 2026): Hi @pauksztello, Even if `createCustomerOnSignUp` is enabled, there can be a delay before the webhook result is received from Stripe. If stripeCustomerId is marked as required, the DB operation itself may fail. Also, createCustomerOnSignUp can be toggled in some use cases, and changing the database schema every time doesn't seem appropriate. Feel free to let me know if I’m missing something 🙏
Author
Owner

@bytaesu commented on GitHub (Jan 15, 2026):

+) in the case of organization customers, they are not created immediately.

Image
@bytaesu commented on GitHub (Jan 15, 2026): +) in the case of organization customers, they are not created immediately. <img width="835" height="337" alt="Image" src="https://github.com/user-attachments/assets/1a0259a1-5733-4720-abe4-278a51e99127" />
Author
Owner

@pauksztello commented on GitHub (Jan 15, 2026):

Hi @bytaesu — thanks, that makes sense.

In our use case we dont’t allow users to exist without a stripeCustomerId and we have to check everywhere if it exists.

Question: what is the reason that this can’t work like a before user create hook, where user creation throws returned false (In case stripeCustomerId does not exist?

@pauksztello commented on GitHub (Jan 15, 2026): Hi @bytaesu — thanks, that makes sense. In our use case we dont’t allow users to exist without a stripeCustomerId and we have to check everywhere if it exists. Question: what is the reason that this can’t work like a before user create hook, where user creation throws returned false (In case stripeCustomerId does not exist?
Author
Owner

@bytaesu commented on GitHub (Jan 15, 2026):

Hi @pauksztello, I was thinking about this.

We support transactions, but it's difficult to guarantee 100% success with external APIs like Stripe at user creation. And there's also logic to link existing Stripe customers through user’s email, which can't be fully guaranteed to run atomically at the creation time.

Therefore, even if a user is created without a stripeCustomerId, current Stripe plugin re-attempt automatic regeneration when upgrading!

@bytaesu commented on GitHub (Jan 15, 2026): Hi @pauksztello, I was thinking about this. We support transactions, but it's difficult to guarantee 100% success with external APIs like Stripe at user creation. And there's also logic to link existing Stripe customers through user’s email, which can't be fully guaranteed to run atomically at the creation time. Therefore, even if a user is created without a `stripeCustomerId`, current Stripe plugin re-attempt automatic regeneration when upgrading!
Author
Owner

@pauksztello commented on GitHub (Jan 16, 2026):

Thanks for clarifying @bytaesu

Just one last question: are there any cases where stripeCustomerId can remain null if using the Stripe plugin without subscription management or organizations? Are we safe to typecast?

@pauksztello commented on GitHub (Jan 16, 2026): Thanks for clarifying @bytaesu Just one last question: are there any cases where stripeCustomerId can remain null if using the Stripe plugin without subscription management or organizations? Are we safe to typecast?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2713