[PR #5784] feat: added lastUsed flag to the organization schema #6221

Open
opened 2026-03-13 12:51:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5784
Author: @bossadizenith
Created: 11/5/2025
Status: 🔄 Open

Base: canaryHead: feature/lastUsed


📝 Commits (9)

  • 23a61d2 feat: added lastUsed flag to the organization schema
  • b4c333f Merge branch 'canary' into feature/lastUsed
  • c2883ec Apply suggestions from code review
  • 1fb3b49 feat: made the modifications based on the the suggestions from @Bekacru
  • b6c431e Merge branch 'feature/lastUsed' of https://github.com/code-env/better-auth into feature/lastUsed
  • 1c181dc feat: remove the content in the .gitignore file and updated the pnpm-lock.ymal
  • f72d757 fix: merge conflicts
  • 95d046a feat: fixed linting and typecheck
  • aeb0dcd feat: fixed the linting error

📊 Changes

9 files changed (+2393 additions, -102 deletions)

View changed files

demo/tracklastused (+1 -0)
📝 packages/better-auth/src/plugins/organization/adapter.ts (+16 -0)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+5 -2)
📝 packages/better-auth/src/plugins/organization/organization.ts (+10 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+32 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+60 -1)
📝 packages/better-auth/src/plugins/organization/schema.ts (+5 -0)
📝 packages/better-auth/src/plugins/organization/types.ts (+9 -0)
📝 pnpm-lock.yaml (+2255 -99)

📄 Description

Add support for tracking last used organization that references this PR

This update lets better-auth organization plugin remember the last organization a user interacted with.
When enabled with trackLastUsedOrganization, it marks that org as lastUsed, sorts it first in listings, and auto-selects it when the user signs back in.

Includes:

  • lastUsed field in member schema
  • Adapter methods to update/reset last used org
  • Route logic updates to keep the state in sync

Improves UX for multi-org users and removes the need for manual tracking.

https://github.com/user-attachments/assets/b933de70-bcc0-4d9d-b2fe-d1224c6ef8b4


Summary by cubic

Adds tracking of the user’s last active organization and prioritizes it in listings and selection when enabled. Improves multi-org UX by auto-selecting the most recent org.

  • New Features

    • Optional lastActiveOrganization boolean on member.
    • New option: trackLastActiveOrganization.
    • listOrganizations sorts by lastActiveOrganization when enabled.
    • createOrganization, acceptInvitation, and setActiveOrganization mark the chosen org as lastActiveOrganization and clear others.
  • Migration

    • Add a lastActiveOrganization boolean column to the member model and run a migration.
    • Enable trackLastActiveOrganization in the organization plugin options.

Written for commit aeb0dcdc7a. 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/5784 **Author:** [@bossadizenith](https://github.com/bossadizenith) **Created:** 11/5/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feature/lastUsed` --- ### 📝 Commits (9) - [`23a61d2`](https://github.com/better-auth/better-auth/commit/23a61d23b0fe759d6f2e32a4823de3711bad9f84) feat: added lastUsed flag to the organization schema - [`b4c333f`](https://github.com/better-auth/better-auth/commit/b4c333ffdcc0f0ff8cb08ef5286b78c889877232) Merge branch 'canary' into feature/lastUsed - [`c2883ec`](https://github.com/better-auth/better-auth/commit/c2883ec70709735877632e49df7d12398a854823) Apply suggestions from code review - [`1fb3b49`](https://github.com/better-auth/better-auth/commit/1fb3b499558dd41fabc6a1ae587a712fbe0f3c38) feat: made the modifications based on the the suggestions from @Bekacru - [`b6c431e`](https://github.com/better-auth/better-auth/commit/b6c431e07489154854857efdd46d9a85a757fa96) Merge branch 'feature/lastUsed' of https://github.com/code-env/better-auth into feature/lastUsed - [`1c181dc`](https://github.com/better-auth/better-auth/commit/1c181dc3cff00eac7e1972841f7b0c0bc2063b2b) feat: remove the content in the .gitignore file and updated the pnpm-lock.ymal - [`f72d757`](https://github.com/better-auth/better-auth/commit/f72d757e11d9617340b83cddd7735456202ad685) fix: merge conflicts - [`95d046a`](https://github.com/better-auth/better-auth/commit/95d046a93bf491764f1eae954f35d90bf0a6270a) feat: fixed linting and typecheck - [`aeb0dcd`](https://github.com/better-auth/better-auth/commit/aeb0dcdc7ace8278f14f8108e554080a4b767689) feat: fixed the linting error ### 📊 Changes **9 files changed** (+2393 additions, -102 deletions) <details> <summary>View changed files</summary> ➕ `demo/tracklastused` (+1 -0) 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+16 -0) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+5 -2) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+10 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+32 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+60 -1) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+5 -0) 📝 `packages/better-auth/src/plugins/organization/types.ts` (+9 -0) 📝 `pnpm-lock.yaml` (+2255 -99) </details> ### 📄 Description Add support for tracking last used organization that references this [PR](https://github.com/better-auth/better-auth/issues/5728) This update lets better-auth organization plugin remember the **last organization a user interacted with**. When enabled with `trackLastUsedOrganization`, it marks that org as `lastUsed`, sorts it first in listings, and auto-selects it when the user signs back in. Includes: * `lastUsed` field in member schema * Adapter methods to update/reset last used org * Route logic updates to keep the state in sync Improves UX for multi-org users and removes the need for manual tracking. https://github.com/user-attachments/assets/b933de70-bcc0-4d9d-b2fe-d1224c6ef8b4 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds tracking of the user’s last active organization and prioritizes it in listings and selection when enabled. Improves multi-org UX by auto-selecting the most recent org. - **New Features** - Optional lastActiveOrganization boolean on member. - New option: trackLastActiveOrganization. - listOrganizations sorts by lastActiveOrganization when enabled. - createOrganization, acceptInvitation, and setActiveOrganization mark the chosen org as lastActiveOrganization and clear others. - **Migration** - Add a lastActiveOrganization boolean column to the member model and run a migration. - Enable trackLastActiveOrganization in the organization plugin options. <sup>Written for commit aeb0dcdc7ace8278f14f8108e554080a4b767689. 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 12:51:32 -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#6221