[PR #6494] feat(organization): allow setting default organization and set last active on sign-in #6702

Open
opened 2026-03-13 13:08:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6494
Author: @jslno
Created: 12/3/2025
Status: 🔄 Open

Base: canaryHead: 12-02-2025/auto-create-org


📝 Commits (10+)

  • 6675f65 feat: auto create and keep active organization/team
  • 41fff1a Merge branch 'canary' into 12-02-2025/auto-create-org
  • 8f86f58 refactor: rename autoCreateOnSignUp to defaultOrganization
  • a9fe2d1 feat: prevent last org deletion
  • b1bdeb6 chore: add test for preventing last org deletion
  • 0bbb52a chore: update jsdoc
  • 0fc0148 chore: fix linting
  • 7c7cdb9 chore: update test
  • 7d396bf Merge branch 'canary' into 12-02-2025/auto-create-org
  • afbde4d chore: fix linting

📊 Changes

5 files changed (+473 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/organization.test.ts (+206 -0)
📝 packages/better-auth/src/plugins/organization/organization.ts (+173 -1)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+17 -0)
📝 packages/better-auth/src/plugins/organization/schema.ts (+30 -1)
📝 packages/better-auth/src/plugins/organization/types.ts (+47 -0)

📄 Description

Fixes: #3076 #5775

closes #2010


Summary by cubic

Creates a default organization when a user has none (on sign-up or sign-in), restores the last active organization/team on sign-in, and prevents deleting a user's last remaining organization.

  • New Features

    • defaultOrganization: creates an organization when none exists and sets it active; prevents last-org deletion by default; creates a default team when teams are enabled (configurable); supports a custom default organization creator.
    • keepActiveOrganization: saves the active organization on sign-out and restores it on the next sign-in.
    • teams.keepActiveTeam: saves/restores the active team; automatically enables keepActiveOrganization.
  • Migration

    • When enabling keepActiveOrganization or teams.keepActiveTeam, add user fields for persistence: lastOrganizationId, and lastTeamId when teams.keepActiveTeam is enabled.

Written for commit 14d23c4243. Summary will update automatically 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/6494 **Author:** [@jslno](https://github.com/jslno) **Created:** 12/3/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `12-02-2025/auto-create-org` --- ### 📝 Commits (10+) - [`6675f65`](https://github.com/better-auth/better-auth/commit/6675f6526bf7876cf4995e560c31369aa89314a1) feat: auto create and keep active organization/team - [`41fff1a`](https://github.com/better-auth/better-auth/commit/41fff1a936830e21e68d40f57da2de991f1bb8a7) Merge branch 'canary' into 12-02-2025/auto-create-org - [`8f86f58`](https://github.com/better-auth/better-auth/commit/8f86f587d24bddb6469c80b1a74fbac59746d7d5) refactor: rename `autoCreateOnSignUp` to `defaultOrganization` - [`a9fe2d1`](https://github.com/better-auth/better-auth/commit/a9fe2d18927d9be3548c15de5d55cc226f48b195) feat: prevent last org deletion - [`b1bdeb6`](https://github.com/better-auth/better-auth/commit/b1bdeb686be05aa5cd4e85b666a020faf2fcd238) chore: add test for preventing last org deletion - [`0bbb52a`](https://github.com/better-auth/better-auth/commit/0bbb52a26b404b141fc714d7b721abb679481cee) chore: update jsdoc - [`0fc0148`](https://github.com/better-auth/better-auth/commit/0fc01489bdf2448152a6d101acaf68c508022ab1) chore: fix linting - [`7c7cdb9`](https://github.com/better-auth/better-auth/commit/7c7cdb9de7947058b5795c293178b88bcf9d0497) chore: update test - [`7d396bf`](https://github.com/better-auth/better-auth/commit/7d396bff39c21cb42b76b8f24c5b3b49ad3e758a) Merge branch 'canary' into 12-02-2025/auto-create-org - [`afbde4d`](https://github.com/better-auth/better-auth/commit/afbde4dcea9f5721bde1cd659ac07fe840da6603) chore: fix linting ### 📊 Changes **5 files changed** (+473 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+206 -0) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+173 -1) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+17 -0) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+30 -1) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+47 -0) </details> ### 📄 Description Fixes: #3076 #5775 closes #2010 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Creates a default organization when a user has none (on sign-up or sign-in), restores the last active organization/team on sign-in, and prevents deleting a user's last remaining organization. - **New Features** - defaultOrganization: creates an organization when none exists and sets it active; prevents last-org deletion by default; creates a default team when teams are enabled (configurable); supports a custom default organization creator. - keepActiveOrganization: saves the active organization on sign-out and restores it on the next sign-in. - teams.keepActiveTeam: saves/restores the active team; automatically enables keepActiveOrganization. - **Migration** - When enabling keepActiveOrganization or teams.keepActiveTeam, add user fields for persistence: lastOrganizationId, and lastTeamId when teams.keepActiveTeam is enabled. <sup>Written for commit 14d23c42432af2e53a7a90377f89fe4aceef49ef. Summary will update automatically 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-03-13 13:08:48 -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#6702