[PR #5932] fix(organization): set session cookie after updating #14578

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

Original Pull Request: https://github.com/better-auth/better-auth/pull/5932

State: open
Merged: No


This PR fixes all missing places in organization plugin which alter the session via setActiveOrganization and setActiveTeam to also update the session cookie with the updated session.

We've discovered this issue while using the create organization endpoint with keepCurrentActiveOrganization: false which should have switched to the new organization, but it did not.

While browsing the organization plugin codebase I found out that some places do have this logic already in place, but most of the places did only the DB update without setting the cookie.


Summary by cubic

Ensures the session cookie is updated whenever the active organization or team changes, so the session reflects changes immediately. Fixes cases where creating an org with keepCurrentActiveOrganization: false or membership changes didn’t switch the active org/team.

  • Bug Fixes
    • Write the updated session to the cookie after setActiveOrganization/setActiveTeam in crud-org, crud-members, and crud-invites.
    • When the active org becomes null (remove member, leave org, delete org, or access an org you’re not a member of), update the cookie to reflect the change.
    • createOrganization now correctly switches to the new org/team when keepCurrentActiveOrganization is false.

Written for commit dfad351f05. Summary will update on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5932 **State:** open **Merged:** No --- This PR fixes all missing places in organization plugin which alter the session via `setActiveOrganization` and `setActiveTeam` to also update the session cookie with the updated session. We've discovered this issue while using the create organization endpoint with `keepCurrentActiveOrganization: false` which should have switched to the new organization, but it did not. While browsing the organization plugin codebase I found out that some places do have this logic already in place, but most of the places did only the DB update without setting the cookie. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Ensures the session cookie is updated whenever the active organization or team changes, so the session reflects changes immediately. Fixes cases where creating an org with keepCurrentActiveOrganization: false or membership changes didn’t switch the active org/team. - **Bug Fixes** - Write the updated session to the cookie after setActiveOrganization/setActiveTeam in crud-org, crud-members, and crud-invites. - When the active org becomes null (remove member, leave org, delete org, or access an org you’re not a member of), update the cookie to reflect the change. - createOrganization now correctly switches to the new org/team when keepCurrentActiveOrganization is false. <sup>Written for commit dfad351f05a5013bd6a1799b543ccd304a6e611f. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:32:00 -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#14578