[PR #6786] [MERGED] feat(organization): Add function support to membershipLimit option in organization plugin #6881

Closed
opened 2026-03-13 13:15:14 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6786
Author: @amrnt
Created: 12/15/2025
Status: Merged
Merged: 1/11/2026
Merged by: @Bekacru

Base: canaryHead: feature/membership-limit-function


📝 Commits (6)

  • 82c5c42 feat: allow membershipLimit to accept a function for dynamic limits
  • 1451aa3 prevent membershipLimit function from breaking adapter queries
  • 496fbd4 update description
  • fdd5473 changes
  • 0f5f42e Merge branch 'canary' into feature/membership-limit-function
  • 24f5fb8 Merge branch 'canary' into feature/membership-limit-function

📊 Changes

7 files changed (+148 additions, -21 deletions)

View changed files

📝 docs/content/docs/plugins/organization.mdx (+1 -1)
📝 packages/better-auth/src/plugins/organization/adapter.ts (+10 -2)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+104 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+12 -7)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+14 -9)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/types.ts (+6 -1)

📄 Description

Summary

This PR enhances the membershipLimit option in the organization plugin to accept a function that dynamically determines the maximum number of members allowed in an organization. This provides flexibility similar to other limit options like invitationLimit.

Updated OrganizationOptions.membershipLimit to accept either a number or a function (user: User, organization: Organization) => Promise<number> | number.

Fixes #5517


Summary by cubic

Adds function support to the organization plugin’s membershipLimit so orgs can set dynamic member caps. Limits are checked when adding members and when accepting invitations; docs and tests updated.

  • New Features

    • membershipLimit now accepts a number or a function: (user, organization) => Promise | number.
    • Runtime limit enforcement added to addMember and acceptInvitation routes.
  • Bug Fixes

    • Adapter safeguards ensure a numeric limit is used in queries when membershipLimit is a function (defaults to 100).

Written for commit 24f5fb8511. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6786 **Author:** [@amrnt](https://github.com/amrnt) **Created:** 12/15/2025 **Status:** ✅ Merged **Merged:** 1/11/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feature/membership-limit-function` --- ### 📝 Commits (6) - [`82c5c42`](https://github.com/better-auth/better-auth/commit/82c5c42413e819038dc0c018f743c66e95afd3b9) feat: allow membershipLimit to accept a function for dynamic limits - [`1451aa3`](https://github.com/better-auth/better-auth/commit/1451aa3b020d993db84b08bbc10711fa56ff9c7f) prevent membershipLimit function from breaking adapter queries - [`496fbd4`](https://github.com/better-auth/better-auth/commit/496fbd492e59aeb46682c58cde0a6bc59a84c952) update description - [`fdd5473`](https://github.com/better-auth/better-auth/commit/fdd5473b976eb7e5522e184773104330384bd470) changes - [`0f5f42e`](https://github.com/better-auth/better-auth/commit/0f5f42eada61c6955421e33a206045c18e31e76b) Merge branch 'canary' into feature/membership-limit-function - [`24f5fb8`](https://github.com/better-auth/better-auth/commit/24f5fb8511516e82c3f69850b981f3549c1f4561) Merge branch 'canary' into feature/membership-limit-function ### 📊 Changes **7 files changed** (+148 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/organization.mdx` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+10 -2) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+104 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+12 -7) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+14 -9) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+6 -1) </details> ### 📄 Description ## Summary This PR enhances the `membershipLimit` option in the organization plugin to accept a function that dynamically determines the maximum number of members allowed in an organization. This provides flexibility similar to other limit options like `invitationLimit`. Updated `OrganizationOptions.membershipLimit` to accept either a `number` or a function `(user: User, organization: Organization) => Promise<number> | number`. Fixes #5517 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds function support to the organization plugin’s membershipLimit so orgs can set dynamic member caps. Limits are checked when adding members and when accepting invitations; docs and tests updated. - **New Features** - membershipLimit now accepts a number or a function: (user, organization) => Promise<number> | number. - Runtime limit enforcement added to addMember and acceptInvitation routes. - **Bug Fixes** - Adapter safeguards ensure a numeric limit is used in queries when membershipLimit is a function (defaults to 100). <sup>Written for commit 24f5fb8511516e82c3f69850b981f3549c1f4561. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:15:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#6881