[PR #7989] [MERGED] fix(organization): refetch activeMember and activeMemberRole when active organization changes #24570

Closed
opened 2026-04-15 22:26:22 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7989
Author: @bytaesu
Created: 2/16/2026
Status: Merged
Merged: 2/16/2026
Merged by: @himself65

Base: canaryHead: 2026-02-16/fix/org-active-member-stale-on-switch


📝 Commits (2)

  • 576717c fix(organization): refetch activeMember and activeMemberRole when active organization changes
  • 63d7f71 test: add headers

📊 Changes

2 files changed (+193 additions, -16 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/client.ts (+10 -15)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+183 -1)

📄 Description

Note

$activeMemberSignal and $activeMemberRoleSignal are no longer auto-triggered but still exported from getAtoms() for manual use

Replace dedicated $activeMemberSignal/$activeMemberRoleSignal listeners with $activeOrgSignal dependency so activeMember and activeMemberRole refetch on any organization change, including setActive.

cc @ping-maxwell


Summary by cubic

Fixes stale activeMember and activeMemberRole when switching organizations by making these queries depend on $activeOrgSignal. Addresses #7981 and keeps session and member state in sync after org changes.

  • Bug Fixes

    • Tie activeMember and activeMemberRole queries to [$activeOrgSignal, $activeMemberSignal] and [$activeOrgSignal, $activeMemberRoleSignal] so they refetch on org changes.
    • Refresh session on org mutations: set-active, create, delete, remove-member, leave, accept-invitation.
    • Remove dedicated listeners for update-member-role; refetch now flows from org/session changes.
    • Add tests for setActive and create flows, with request headers and client-side query setup for accurate session scoping.
  • Migration

    • $activeMemberSignal and $activeMemberRoleSignal no longer auto-trigger; they’re still exported via getAtoms() for manual use. Rely on $activeOrgSignal-driven queries for automatic updates.

Written for commit 63d7f71118. 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/7989 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 2/16/2026 **Status:** ✅ Merged **Merged:** 2/16/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2026-02-16/fix/org-active-member-stale-on-switch` --- ### 📝 Commits (2) - [`576717c`](https://github.com/better-auth/better-auth/commit/576717c21f478a69db4cde0a5b5e493c2a466976) fix(organization): refetch activeMember and activeMemberRole when active organization changes - [`63d7f71`](https://github.com/better-auth/better-auth/commit/63d7f7111871f3062e6f4a31bf9c10ad2c3ac331) test: add headers ### 📊 Changes **2 files changed** (+193 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/client.ts` (+10 -15) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+183 -1) </details> ### 📄 Description > [!NOTE] > `$activeMemberSignal` and `$activeMemberRoleSignal` are no longer auto-triggered but still exported from `getAtoms()` for manual use Replace dedicated `$activeMemberSignal`/`$activeMemberRoleSignal` listeners with `$activeOrgSignal` dependency so activeMember and activeMemberRole refetch on any organization change, including setActive. - Closes #7981 cc @ping-maxwell <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes stale activeMember and activeMemberRole when switching organizations by making these queries depend on $activeOrgSignal. Addresses #7981 and keeps session and member state in sync after org changes. - **Bug Fixes** - Tie activeMember and activeMemberRole queries to [$activeOrgSignal, $activeMemberSignal] and [$activeOrgSignal, $activeMemberRoleSignal] so they refetch on org changes. - Refresh session on org mutations: set-active, create, delete, remove-member, leave, accept-invitation. - Remove dedicated listeners for update-member-role; refetch now flows from org/session changes. - Add tests for setActive and create flows, with request headers and client-side query setup for accurate session scoping. - **Migration** - $activeMemberSignal and $activeMemberRoleSignal no longer auto-trigger; they’re still exported via getAtoms() for manual use. Rely on $activeOrgSignal-driven queries for automatic updates. <sup>Written for commit 63d7f7111871f3062e6f4a31bf9c10ad2c3ac331. 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-04-15 22:26:22 -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#24570