SSO Provider should be more flexible when organizationId is provided #2476

Open
opened 2026-03-13 09:57:14 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @penguine-ip on GitHub (Dec 7, 2025).

Is this suited for github?

  • Yes, this is suited for github

Often times when folks introduce better auth to their systems they are switching away from an auth provider with existing apps and database schemas. It is therefore very likely that an Organization table already exist despite not having a member table (more on this later).

Understandably, if I wish to allow a self-served SSO flow for users it is not farfetched to want the SSO provider to be one-per-organization, so different users within the same org don't mess with SSO configs twice.

A way to do this right now is to simply set the organizationId field in the SsoProvider table, which is great. However when I do provide an organizationId a bunch of problems come up, including the requirement of a member table which I couldn't care less about. This for example is needed when I want to request domain verification via better auth for a sso provider that has an organization ID: ba738464b9/packages/sso/src/routes/domain-verification.ts (L59)

I can workaround this by simply not setting the organizationId, and instead find all SsoProviders associated with all users in an organization before using some logic to always only allow one sso provider per org, but that seems unnecessary.

Describe the solution you'd like

Just be more lenient and check if members table exist before trying to access it. Apart from the request domain endpoint, same should be done here: ba738464b9/packages/sso/src/routes/domain-verification.ts (L59)

Describe alternatives you've considered

I can workaround this by simply not setting the organizationId, and instead find all SsoProviders associated with all users in an organization before using some logic to always only allow one sso provider per org, but that seems unnecessary.

Additional context

No response

Originally created by @penguine-ip on GitHub (Dec 7, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Often times when folks introduce better auth to their systems they are switching away from an auth provider with existing apps and database schemas. It is therefore very likely that an `Organization` table already exist despite not having a `member` table (more on this later). Understandably, if I wish to allow a self-served SSO flow for users it is not farfetched to want the SSO provider to be one-per-organization, so different users within the same org don't mess with SSO configs twice. A way to do this right now is to simply set the `organizationId` field in the `SsoProvider` table, which is great. However when I do provide an `organizationId` a bunch of problems come up, including the requirement of a `member` table which I couldn't care less about. This for example is needed when I want to request domain verification via better auth for a sso provider that has an organization ID: https://github.com/better-auth/better-auth/blob/ba738464b97dc67a6b9f49b71f0253283fa936c5/packages/sso/src/routes/domain-verification.ts#L59 I can workaround this by simply not setting the `organizationId`, and instead find all `SsoProviders` associated with all users in an organization before using some logic to always only allow one sso provider per org, but that seems unnecessary. ### Describe the solution you'd like Just be more lenient and check if members table exist before trying to access it. Apart from the request domain endpoint, same should be done here: https://github.com/better-auth/better-auth/blob/ba738464b97dc67a6b9f49b71f0253283fa936c5/packages/sso/src/routes/domain-verification.ts#L59 ### Describe alternatives you've considered I can workaround this by simply not setting the `organizationId`, and instead find all `SsoProviders` associated with all users in an organization before using some logic to always only allow one sso provider per org, but that seems unnecessary. ### Additional context _No response_
GiteaMirror added the staleenhancement labels 2026-03-13 09:57:14 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 7, 2025):

(tag @better-auth-agent if you would like an answer from the Agent)

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 (Dec 7, 2025): (tag @better-auth-agent if you would like an answer from the Agent) _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/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Mar 8, 2026):

Hi, @penguine-ip. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested enhanced flexibility for SSO providers when an organizationId is set.
  • Specifically, you suggested the system should check for the existence of the member table before accessing it, as not all setups include this table.
  • Currently, you avoid setting organizationId and manage SSO providers per organization through user associations as a workaround.
  • There has been no response from maintainers or further discussion on this issue.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Mar 8, 2026): Hi, @penguine-ip. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested enhanced flexibility for SSO providers when an organizationId is set. - Specifically, you suggested the system should check for the existence of the member table before accessing it, as not all setups include this table. - Currently, you avoid setting organizationId and manage SSO providers per organization through user associations as a workaround. - There has been no response from maintainers or further discussion on this issue. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2476