[PR #5063] [MERGED] fix(organization): deleting member from org doesn't delete them from teams #31351

Closed
opened 2026-04-17 22:13:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5063
Author: @ping-maxwell
Created: 10/3/2025
Status: Merged
Merged: 11/7/2025
Merged by: @Bekacru

Base: canaryHead: fix/organization/delete-member-should-delete-in-teams-too


📝 Commits (10+)

  • 7c46e03 fix(organization): deleting member from org doesn't delete them from teams
  • 763266c add: test for leave org
  • 5656ed1 Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too
  • 9510d60 fix: remove logger lvl in tests
  • 684879c Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too
  • 5d2ffd2 Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too
  • 071110a Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too
  • fa6db48 Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too
  • 061e4ae fix: change req
  • 18bbb88 Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too

📊 Changes

3 files changed (+274 additions, -6 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/adapter.ts (+40 -3)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+10 -3)
📝 packages/better-auth/src/plugins/organization/team.test.ts (+224 -0)

📄 Description

When calling auth.api.removeMember it's expected that they're removed from both the organization they're in, as well as any teams they could be in.

This applies to the leaveOrganization endpoint too.

  • tests for removeMember
  • tests for leaveOrganization

closes https://github.com/better-auth/better-auth/issues/5038
Linear issue: https://linear.app/better-auth/issue/ENG-170/fix-removemember-should-cascade-deletion-from-teammembers


Summary by cubic

Removing a member from an organization now also removes them from all teams in that org. This applies to both removeMember and leaveOrganization to prevent orphaned team memberships.

  • Bug Fixes
    • deleteMember removes related teamMember records across all teams in the organization.
    • Updated removeMember and leaveOrganization routes to pass organizationId and userId to deleteMember.
    • Added tests to confirm team memberships are cleared when a member leaves or is removed.

🔄 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/5063 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/3/2025 **Status:** ✅ Merged **Merged:** 11/7/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/organization/delete-member-should-delete-in-teams-too` --- ### 📝 Commits (10+) - [`7c46e03`](https://github.com/better-auth/better-auth/commit/7c46e038ab078c9c36507ca8ad43ca4cfff4bfeb) fix(organization): deleting member from org doesn't delete them from teams - [`763266c`](https://github.com/better-auth/better-auth/commit/763266cbfcb4845c8547132506c4da41a9893c94) add: test for leave org - [`5656ed1`](https://github.com/better-auth/better-auth/commit/5656ed14c4f33c845ae8213b535b4a83b6363a60) Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too - [`9510d60`](https://github.com/better-auth/better-auth/commit/9510d60ad848b77a77b3c0ea7eb1c247dea6ea5c) fix: remove logger lvl in tests - [`684879c`](https://github.com/better-auth/better-auth/commit/684879c8288ca77c7e74f7f4252a8bd7624929bc) Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too - [`5d2ffd2`](https://github.com/better-auth/better-auth/commit/5d2ffd230f0058982727e7a2d2daa2d3b851e160) Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too - [`071110a`](https://github.com/better-auth/better-auth/commit/071110aaad297bf36d774d7a1a867f55d8938ba2) Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too - [`fa6db48`](https://github.com/better-auth/better-auth/commit/fa6db48122756be418295daead5e16d2a30da590) Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too - [`061e4ae`](https://github.com/better-auth/better-auth/commit/061e4aec81a14cf838f5c7b3cdf71dcca708f535) fix: change req - [`18bbb88`](https://github.com/better-auth/better-auth/commit/18bbb88911f33952a4e2a1a7060b83833afe6dbf) Merge branch 'canary' into fix/organization/delete-member-should-delete-in-teams-too ### 📊 Changes **3 files changed** (+274 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+40 -3) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+10 -3) 📝 `packages/better-auth/src/plugins/organization/team.test.ts` (+224 -0) </details> ### 📄 Description When calling auth.api.removeMember it's expected that they're removed from both the organization they're in, as well as any teams they could be in. This applies to the `leaveOrganization` endpoint too. - [x] tests for `removeMember` - [x] tests for `leaveOrganization` closes https://github.com/better-auth/better-auth/issues/5038 Linear issue: https://linear.app/better-auth/issue/ENG-170/fix-removemember-should-cascade-deletion-from-teammembers <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Removing a member from an organization now also removes them from all teams in that org. This applies to both removeMember and leaveOrganization to prevent orphaned team memberships. - **Bug Fixes** - deleteMember removes related teamMember records across all teams in the organization. - Updated removeMember and leaveOrganization routes to pass organizationId and userId to deleteMember. - Added tests to confirm team memberships are cleared when a member leaves or is removed. <!-- 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-04-17 22:13:34 -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#31351