[GH-ISSUE #7750] Expose organizationId in SSO providersLimit function #10891

Open
opened 2026-04-13 07:16:10 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @robingenz on GitHub (Feb 1, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7750

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

When using the SSO plugin with organizations, the providersLimit function only receives the user object. This makes it impossible to enforce organization-specific constraints, such as allowing SSO provider registration only for organizations on an enterprise plan.

Currently, if a user is a member of multiple organizations (e.g., one on a free plan and one on an enterprise plan), there's no way to differentiate which organization they're registering the SSO provider for within the providersLimit function. The organizationId is validated later in the flow but isn't accessible when the limit check occurs.

Describe the solution you'd like

Enhance the providersLimit function signature to include the organizationId:

// Current
providersLimit?: number | ((user: User) => Awaitable<number>);

// Proposed
providersLimit?: number | ((data: {
  user: User;
  organizationId?: string;
}) => Awaitable<number>);

This would enable plan-based validation:

sso({
  providersLimit: async ({ user, organizationId }) => {
    if (!organizationId) return 0; // Require organization for SSO
    
    const context = getContext();
    const org = await context.adapter.findOne({
      model: "organization",
      where: [{ field: "id", value: organizationId }]
    });
    
    return org?.plan === "enterprise" ? 10 : 0;
  }
})

Describe alternatives you've considered

Custom endpoint wrapper that replaces the built-in registration endpoint. This requires significant code duplication and maintenance.

Additional context

The organizationId is already available in ctx.body.organizationId at the point where providersLimit is called. The membership validation happens shortly after. Moving the limit check to after the membership validation, or passing the organizationId to the limit function, would enable this use case without requiring workarounds.

This enhancement would maintain backward compatibility since organizationId would be optional.

Originally created by @robingenz on GitHub (Feb 1, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7750 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. When using the SSO plugin with organizations, the `providersLimit` function only receives the `user` object. This makes it impossible to enforce organization-specific constraints, such as allowing SSO provider registration only for organizations on an enterprise plan. Currently, if a user is a member of multiple organizations (e.g., one on a free plan and one on an enterprise plan), there's no way to differentiate which organization they're registering the SSO provider for within the `providersLimit` function. The `organizationId` is validated later in the flow but isn't accessible when the limit check occurs. ### Describe the solution you'd like Enhance the `providersLimit` function signature to include the `organizationId`: ```typescript // Current providersLimit?: number | ((user: User) => Awaitable<number>); // Proposed providersLimit?: number | ((data: { user: User; organizationId?: string; }) => Awaitable<number>); ``` This would enable plan-based validation: ```typescript sso({ providersLimit: async ({ user, organizationId }) => { if (!organizationId) return 0; // Require organization for SSO const context = getContext(); const org = await context.adapter.findOne({ model: "organization", where: [{ field: "id", value: organizationId }] }); return org?.plan === "enterprise" ? 10 : 0; } }) ``` ### Describe alternatives you've considered Custom endpoint wrapper that replaces the built-in registration endpoint. This requires significant code duplication and maintenance. ### Additional context The organizationId is already available in `ctx.body.organizationId` at the point where `providersLimit` is called. The membership validation happens shortly after. Moving the limit check to after the membership validation, or passing the organizationId to the limit function, would enable this use case without requiring workarounds. This enhancement would maintain backward compatibility since `organizationId` would be optional.
GiteaMirror added the identityorganization labels 2026-04-13 07:16:10 -05:00
Author
Owner

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

It appears there's an open issue regarding the request to expose the organizationId in the providersLimit function of the SSO plugin. The suggestion is to enhance the function signature to allow for organization-specific constraints when registering SSO providers, as currently, the organizationId is not accessible at that stage but validated later in the flow. This would allow developers to implement plan-based validation depending on the organization.

For now, you can track this request through the ongoing discussions and updates on the issue. If you have specific questions or need further clarification, feel free to tag @bekacru or @ping__ for assistance from the Better Auth team!

What kind of constraints would you want to enforce with the providersLimit function?

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3831105396 --> @better-auth-agent[bot] commented on GitHub (Feb 1, 2026): It appears there's an open issue regarding the request to expose the `organizationId` in the `providersLimit` function of the SSO plugin. The suggestion is to enhance the function signature to allow for organization-specific constraints when registering SSO providers, as currently, the `organizationId` is not accessible at that stage but validated later in the flow. This would allow developers to implement plan-based validation depending on the organization. For now, you can track this request through the ongoing discussions and updates on the issue. If you have specific questions or need further clarification, feel free to tag @bekacru or @ping__ for assistance from the Better Auth team! What kind of constraints would you want to enforce with the `providersLimit` function? _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

@robingenz commented on GitHub (Feb 1, 2026):

What kind of constraints would you want to enforce with the providersLimit function?

Whether or not the organization billing plan allows the registration of SSO providers.

<!-- gh-comment-id:3831110921 --> @robingenz commented on GitHub (Feb 1, 2026): > What kind of constraints would you want to enforce with the providersLimit function? Whether or not the organization billing plan allows the registration of SSO providers.
Author
Owner

@opswiz commented on GitHub (Apr 7, 2026):

It would be really nice to have this done, Similar use case wrt org plan, also sometimes want to dynamically disable based on the environment.

<!-- gh-comment-id:4199251373 --> @opswiz commented on GitHub (Apr 7, 2026): It would be really nice to have this done, Similar use case wrt org plan, also sometimes want to dynamically disable based on the environment.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10891