[PR #4724] [MERGED] fix: support for organizations with large member counts #5548

Closed
opened 2026-03-13 12:26:55 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4724
Author: @Badbird5907
Created: 9/17/2025
Status: Merged
Merged: 9/18/2025
Merged by: @Bekacru

Base: canaryHead: canary


📝 Commits (4)

  • c1e368e fix(organization): use checkMembership to verify membership on getFullOrganization
  • 800181d fix: lint
  • ac5f731 Merge branch 'canary' into canary
  • b0895ee fix: use organization.id instead of organizationId to check user membership

📊 Changes

1 file changed (+4 additions, -8 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+4 -8)

📄 Description

Hi,
My app includes an organization with approximately 6,000 members. We've encountered an issue where the activeOrganizationId field is set to null after calling getFullOrganization. More details can be found in the Discord thread.

The current implementation of getFullOrganization only loads the first 100 members, checking if the logged-in user is among them. This approach leads to undefined behavior in organizations with more than 100 members. If the member was not found in the 100 members loaded, it would update their session to clear activeOrganizationId.

This issue was especially hard to pinpoint as my app did not call getFullOrganization directly, but it was indirectly called by other functions (See this Discord message).

I also removed a redundant sanity check that was checked above.


🔄 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/4724 **Author:** [@Badbird5907](https://github.com/Badbird5907) **Created:** 9/17/2025 **Status:** ✅ Merged **Merged:** 9/18/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `canary` --- ### 📝 Commits (4) - [`c1e368e`](https://github.com/better-auth/better-auth/commit/c1e368e3c45c022112c8587808d4280912419bbc) fix(organization): use checkMembership to verify membership on getFullOrganization - [`800181d`](https://github.com/better-auth/better-auth/commit/800181d77de1b1f8f1105d72c7ac4981472a3028) fix: lint - [`ac5f731`](https://github.com/better-auth/better-auth/commit/ac5f73133206aab9c26d34c7b3785c4f59b2880b) Merge branch 'canary' into canary - [`b0895ee`](https://github.com/better-auth/better-auth/commit/b0895ee542c8be19e96fa861334ba0363147c921) fix: use organization.id instead of organizationId to check user membership ### 📊 Changes **1 file changed** (+4 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+4 -8) </details> ### 📄 Description Hi, My app includes an organization with approximately 6,000 members. We've encountered an issue where the `activeOrganizationId` field is set to `null` after calling `getFullOrganization`. More details can be found in the [Discord thread](https://canary.discord.com/channels/1288403910284935179/1417776115069485208). The current implementation of `getFullOrganization` only loads the first 100 members, checking if the logged-in user is among them. This approach leads to undefined behavior in organizations with more than 100 members. If the member was not found in the 100 members loaded, it would update their session to clear `activeOrganizationId`. This issue was especially hard to pinpoint as my app did not call `getFullOrganization` directly, but it was indirectly called by other functions (See this [Discord message](https://canary.discord.com/channels/1288403910284935179/1296058482289676320/1417935886267449425)). I also removed a redundant sanity check that was checked above. --- <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 12:26:55 -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#5548