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

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

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

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5784 **State:** open **Merged:** No --- 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:29:23 -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#14468