[PR #5530] feat(organization): add before/after leave organization hooks #6065

Open
opened 2026-03-13 12:46:14 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5530
Author: @ephraimduncan
Created: 10/24/2025
Status: 🔄 Open

Base: canaryHead: feat/org-leave-hooks


📝 Commits (3)

  • 03e112b feat(organization): add beforeLeaveOrganization and afterLeaveOrganization hooks
  • 2a24ebd test(organization): fix leave hooks tests and types formatting
  • 37bb99f fix: merge conflicts

📊 Changes

4 files changed (+543 additions, -17 deletions)

View changed files

📝 docs/content/docs/plugins/organization.mdx (+25 -0)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+448 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+35 -0)
📝 packages/better-auth/src/plugins/organization/types.ts (+35 -16)

📄 Description

Summary by cubic

Add beforeLeaveOrganization and afterLeaveOrganization hooks to the organization plugin to validate, clean up, and notify when a member leaves. The leave flow now loads user and organization, supports aborting in the before hook, and returns the removed member.

  • New Features
    • beforeLeaveOrganization runs before self-removal; throw to block leaving. Receives {member, user, organization}.
    • afterLeaveOrganization runs after removal and active org reset. Receives the same payload for logging/notifications.
    • Leave endpoint fetches user and organization and calls hooks in order; hooks are skipped on invalid member/org.
    • Docs updated with examples; tests cover success, abort, ordering, and validation.

Written for commit 37bb99f843. Summary will update automatically 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/5530 **Author:** [@ephraimduncan](https://github.com/ephraimduncan) **Created:** 10/24/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/org-leave-hooks` --- ### 📝 Commits (3) - [`03e112b`](https://github.com/better-auth/better-auth/commit/03e112b0223749f52dbc614e3ed430f48a84573b) feat(organization): add beforeLeaveOrganization and afterLeaveOrganization hooks - [`2a24ebd`](https://github.com/better-auth/better-auth/commit/2a24ebdbcded58ba185701a4c43b8f0ea51c6540) test(organization): fix leave hooks tests and types formatting - [`37bb99f`](https://github.com/better-auth/better-auth/commit/37bb99f84395ee0844d3954b2d93a0a1a7712807) fix: merge conflicts ### 📊 Changes **4 files changed** (+543 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/organization.mdx` (+25 -0) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+448 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+35 -0) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+35 -16) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Add beforeLeaveOrganization and afterLeaveOrganization hooks to the organization plugin to validate, clean up, and notify when a member leaves. The leave flow now loads user and organization, supports aborting in the before hook, and returns the removed member. - **New Features** - beforeLeaveOrganization runs before self-removal; throw to block leaving. Receives {member, user, organization}. - afterLeaveOrganization runs after removal and active org reset. Receives the same payload for logging/notifications. - Leave endpoint fetches user and organization and calls hooks in order; hooks are skipped on invalid member/org. - Docs updated with examples; tests cover success, abort, ordering, and validation. <sup>Written for commit 37bb99f84395ee0844d3954b2d93a0a1a7712807. Summary will update automatically 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 12:46: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#6065