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

Open
opened 2026-04-15 21:33:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5932
Author: @tbedrnik
Created: 11/12/2025
Status: 🔄 Open

Base: mainHead: fix/organization-session-cookie-issues


📝 Commits (2)

  • 41420f4 fix(organization): set session cookie after updating
  • dfad351 Merge branch 'canary' into fix/organization-session-cookie-issues

📊 Changes

3 files changed (+70 additions, -8 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+7 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-members.ts (+21 -2)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+42 -5)

📄 Description

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.


🔄 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/5932 **Author:** [@tbedrnik](https://github.com/tbedrnik) **Created:** 11/12/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/organization-session-cookie-issues` --- ### 📝 Commits (2) - [`41420f4`](https://github.com/better-auth/better-auth/commit/41420f4231e87ee1f670e8886fb5df4c585ac2b6) fix(organization): set session cookie after updating - [`dfad351`](https://github.com/better-auth/better-auth/commit/dfad351f05a5013bd6a1799b543ccd304a6e611f) Merge branch 'canary' into fix/organization-session-cookie-issues ### 📊 Changes **3 files changed** (+70 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+7 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-members.ts` (+21 -2) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+42 -5) </details> ### 📄 Description 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. --> --- <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 21:33:51 -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#23232