[PR #5424] fix(organization): refetch organization list on membership changes #14246

Open
opened 2026-04-13 09:22:38 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5424
Author: @aryasaatvik
Created: 10/20/2025
Status: 🔄 Open

Base: mainHead: fix/org-list-refetch-on-membership-change


📝 Commits (1)

  • 401cd8d fix(organization): refetch organization list on membership changes

📊 Changes

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

View changed files

📝 packages/better-auth/src/plugins/organization/client.ts (+4 -1)

📄 Description

Summary

Fixes issue where useListOrganizations() hook does not automatically refetch after organization membership changes, causing stale data in UI components like workspace switchers.

Problem

When a user accepts an organization invitation via organization.acceptInvitation():

  • useActiveOrganization() refetches automatically
  • useListOrganizations() does NOT refetch - shows stale data until manual browser refresh

Root Cause

The atomListeners configuration only triggered $listOrg for create/delete/update operations, but NOT for membership changes like accepting invitations, being removed, or leaving organizations.

Solution

Updated the atomListeners matcher in packages/better-auth/src/plugins/organization/client.ts to trigger $listOrg signal for:

  • /organization/accept-invitation - user joins organization
  • /organization/remove-member - user removed from organization
  • /organization/leave - user leaves organization

Testing

After this fix, components using useListOrganizations() will automatically display updated organization lists when membership changes occur, without requiring manual refresh or workarounds.

Removes the need for manual workarounds like:

authClient.$store.notify("$listOrg");

🔄 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/5424 **Author:** [@aryasaatvik](https://github.com/aryasaatvik) **Created:** 10/20/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/org-list-refetch-on-membership-change` --- ### 📝 Commits (1) - [`401cd8d`](https://github.com/better-auth/better-auth/commit/401cd8de9a3928d02d7c3738906b0d94c4f3abca) fix(organization): refetch organization list on membership changes ### 📊 Changes **1 file changed** (+4 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/client.ts` (+4 -1) </details> ### 📄 Description ## Summary Fixes issue where `useListOrganizations()` hook does not automatically refetch after organization membership changes, causing stale data in UI components like workspace switchers. ## Problem When a user accepts an organization invitation via `organization.acceptInvitation()`: - ✅ `useActiveOrganization()` refetches automatically - ❌ `useListOrganizations()` does NOT refetch - shows stale data until manual browser refresh ## Root Cause The `atomListeners` configuration only triggered `$listOrg` for create/delete/update operations, but NOT for membership changes like accepting invitations, being removed, or leaving organizations. ## Solution Updated the `atomListeners` matcher in `packages/better-auth/src/plugins/organization/client.ts` to trigger `$listOrg` signal for: - `/organization/accept-invitation` - user joins organization - `/organization/remove-member` - user removed from organization - `/organization/leave` - user leaves organization ## Testing After this fix, components using `useListOrganizations()` will automatically display updated organization lists when membership changes occur, without requiring manual refresh or workarounds. ## Related Removes the need for manual workarounds like: ```typescript authClient.$store.notify("$listOrg"); ``` --- <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 09:22:38 -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#14246