[PR #4049] [MERGED] feat(organization): organization life cycle hooks #13401

Closed
opened 2026-04-13 08:54:45 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4049
Author: @Bekacru
Created: 8/17/2025
Status: Merged
Merged: 8/30/2025
Merged by: @Bekacru

Base: canaryHead: organization-hooks


📝 Commits (10+)

  • 5eacbfd feat(organization): organization hooks
  • 3cd7fe6 cleanup
  • 2cd72d6 fix types
  • 7529d3c make org nullable for update hook
  • 920e7ea Merge remote-tracking branch 'origin/canary' into organization-hooks
  • 5e6f7fb Merge branch 'canary' into organization-hooks
  • 3756f23 more hooks
  • e00a63c fix test
  • f2f9e8c update docs
  • 8f27946 Merge branch 'canary' into organization-hooks

📊 Changes

9 files changed (+1765 additions, -519 deletions)

View changed files

📝 .vscode/settings.json (+1 -1)
📝 docs/content/docs/plugins/organization.mdx (+685 -330)
📝 packages/better-auth/src/index.ts (+1 -0)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+77 -90)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+120 -35)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+144 -3)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+67 -18)
📝 packages/better-auth/src/plugins/organization/routes/crud-team.ts (+231 -4)
📝 packages/better-auth/src/plugins/organization/types.ts (+439 -38)

📄 Description

Summary by cubic

Adds organization lifecycle hooks to customize create and update flows. Deprecates organizationCreation in favor of organizationHooks.

  • New Features

    • Added beforeCreateOrganization, afterCreateOrganization, beforeUpdateOrganization, and afterUpdateOrganization hooks.
    • Hooks can override input by returning { data } or abort by throwing APIError. Hook payloads include user and member.
    • Improved error handling: update now returns an error if the organization is not found.
  • Migration

    • Replace organizationCreation.beforeCreate/afterCreate with organizationHooks.beforeCreateOrganization/afterCreateOrganization.
    • When overriding input, return { data } from the hook. User and member types now allow extra fields.

🔄 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/4049 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 8/17/2025 **Status:** ✅ Merged **Merged:** 8/30/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `organization-hooks` --- ### 📝 Commits (10+) - [`5eacbfd`](https://github.com/better-auth/better-auth/commit/5eacbfdfd62f884658454e0e9bb992fe17f652a7) feat(organization): organization hooks - [`3cd7fe6`](https://github.com/better-auth/better-auth/commit/3cd7fe6845b91a58bd8e44ee7b9143c7f188fcae) cleanup - [`2cd72d6`](https://github.com/better-auth/better-auth/commit/2cd72d62f9602bac93130ccdc547de3b8e5ca90c) fix types - [`7529d3c`](https://github.com/better-auth/better-auth/commit/7529d3c9445b2848774aa0f0aabfb920b8eb01c6) make org nullable for update hook - [`920e7ea`](https://github.com/better-auth/better-auth/commit/920e7ea22b31749236a11141a0d9594afab01404) Merge remote-tracking branch 'origin/canary' into organization-hooks - [`5e6f7fb`](https://github.com/better-auth/better-auth/commit/5e6f7fb2cef0fdb38ffb98dcf1f0cd62ed7b35e9) Merge branch 'canary' into organization-hooks - [`3756f23`](https://github.com/better-auth/better-auth/commit/3756f239c51b625e8d539aec50b7a52ee8d53aad) more hooks - [`e00a63c`](https://github.com/better-auth/better-auth/commit/e00a63c2a02c5f91da589e6eb946317ded3b3a57) fix test - [`f2f9e8c`](https://github.com/better-auth/better-auth/commit/f2f9e8c2c3f71e0fe94b0bda6f7be06d4e40a246) update docs - [`8f27946`](https://github.com/better-auth/better-auth/commit/8f279461b0251f62211f762775fa4cf9863f275e) Merge branch 'canary' into organization-hooks ### 📊 Changes **9 files changed** (+1765 additions, -519 deletions) <details> <summary>View changed files</summary> 📝 `.vscode/settings.json` (+1 -1) 📝 `docs/content/docs/plugins/organization.mdx` (+685 -330) 📝 `packages/better-auth/src/index.ts` (+1 -0) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+77 -90) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+120 -35) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+144 -3) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+67 -18) 📝 `packages/better-auth/src/plugins/organization/routes/crud-team.ts` (+231 -4) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+439 -38) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds organization lifecycle hooks to customize create and update flows. Deprecates organizationCreation in favor of organizationHooks. - **New Features** - Added beforeCreateOrganization, afterCreateOrganization, beforeUpdateOrganization, and afterUpdateOrganization hooks. - Hooks can override input by returning { data } or abort by throwing APIError. Hook payloads include user and member. - Improved error handling: update now returns an error if the organization is not found. - **Migration** - Replace organizationCreation.beforeCreate/afterCreate with organizationHooks.beforeCreateOrganization/afterCreateOrganization. - When overriding input, return { data } from the hook. User and member types now allow extra fields. <!-- 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-13 08:54:45 -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#13401