[GH-ISSUE #5728] Add lastUsed field to Organization schema to track most recently active organization #10337

Closed
opened 2026-04-13 06:24:05 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @bossadizenith on GitHub (Nov 2, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5728

Is this suited for github?

  • Yes, this is suited for github

Currently, when a user belongs to multiple organizations, the system typically doesn't handles the last organization the user was active on by default. This can be confusing when users expect to return to the organization they last interacted with (in my case). I’ve had to implement this manually in multiple projects(two actually), and having native support in better-auth would simplify this pattern

Describe the solution you'd like

Add a new boolean field lastUsed to the Organization schema.

  • When a user switches organizations, set lastUsed: true for that organization and false for all others.
  • On sign-in, query for the organization where lastUsed: true.
  • If none exists, then we default to what the user has specified in the databaseHooks.

This ensures that users are automatically directed to their most recently active organization.

Describe alternatives you've considered

  • Storing the last used organization ID in the user session or metadata (requires extra client logic).
  • Handling this entirely on the client side (adds complexity and inconsistency).

Additional context

This small addition would improve the DX experience in multi-organization setups and reduce repeated manual implementations given that it'll be supported out of the box

Originally created by @bossadizenith on GitHub (Nov 2, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5728 ### Is this suited for github? - [ ] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. Currently, when a user belongs to multiple organizations, the system typically doesn't handles the last organization the user was active on by default. This can be confusing when users expect to return to the organization they last interacted with (in my case). I’ve had to implement this manually in multiple projects(two actually), and having native support in better-auth would simplify this pattern ### Describe the solution you'd like Add a new boolean field `lastUsed` to the Organization schema. * When a user switches organizations, set `lastUsed: true` for that organization and `false` for all others. * On sign-in, query for the organization where `lastUsed: true`. * If none exists, then we default to what the user has specified in the `databaseHooks`. This ensures that users are automatically directed to their most recently active organization. ### Describe alternatives you've considered * Storing the last used organization ID in the user session or metadata (requires extra client logic). * Handling this entirely on the client side (adds complexity and inconsistency). ### Additional context This small addition would improve the DX experience in multi-organization setups and reduce repeated manual implementations given that it'll be supported out of the box
GiteaMirror added the enhancementlocked labels 2026-04-13 06:24:05 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 2, 2025):

This request seems like a solid enhancement that would simplify multi‑organization setups. The idea is to add a boolean field (lastUsed) to the organization schema so that when the user switches organizations, the active org gets marked as lastUsed and the others are reset. That way, on sign‑in you can quickly determine the org the user last interacted with without requiring manual client‑side logic or extra session metadata.

A recommended next step is to open a feature request on the GitHub repository for Better Auth. In your issue, clearly outline the following points:
• How the field should be updated automatically (for example, via database hooks when a user switches organizations or signs in).
• The expected behavior if no organization is marked as lastUsed (e.g., defaulting based on established databaseHooks settings).
• Any edge cases such as concurrent sessions or multiple devices.

This approach follows similar patterns already implemented for tracking user activity (like the lastLoginAt field) and would reduce manual implementation overhead [1][2].

If you already have a workaround using additionalFields in the organization schema along with custom hooks, sharing that in your request could help guide a native solution.

Please let us know if you need further troubleshooting help or additional details on implementing the change manually until the native support is provided.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3478118720 --> @better-auth-agent[bot] commented on GitHub (Nov 2, 2025): This request seems like a solid enhancement that would simplify multi‑organization setups. The idea is to add a boolean field (lastUsed) to the organization schema so that when the user switches organizations, the active org gets marked as lastUsed and the others are reset. That way, on sign‑in you can quickly determine the org the user last interacted with without requiring manual client‑side logic or extra session metadata. A recommended next step is to open a feature request on the GitHub repository for Better Auth. In your issue, clearly outline the following points: • How the field should be updated automatically (for example, via database hooks when a user switches organizations or signs in). • The expected behavior if no organization is marked as lastUsed (e.g., defaulting based on established databaseHooks settings). • Any edge cases such as concurrent sessions or multiple devices. This approach follows similar patterns already implemented for tracking user activity (like the lastLoginAt field) and would reduce manual implementation overhead [[1]](https://github.com/better-auth/better-auth/issues/2487)[[2]](https://github.com/better-auth/better-auth/pull/4318). If you already have a workaround using additionalFields in the organization schema along with custom hooks, sharing that in your request could help guide a native solution. Please let us know if you need further troubleshooting help or additional details on implementing the change manually until the native support is provided. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Feb 1, 2026):

Hi, @bossadizenith. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You requested adding a lastUsed boolean field to the Organization schema to track the most recently active organization per user.
  • This feature aims to enable automatic selection of the last used organization on sign-in, improving multi-organization user experience.
  • I support this enhancement and suggest outlining automatic updates, default behaviors, and handling edge cases like concurrent sessions.
  • You also recommended sharing any current workarounds using custom hooks to help guide native implementation.
  • This feature aligns with existing patterns such as the lastLoginAt field and would reduce manual client-side logic.

Next Steps:

  • Please let me know if this feature request is still relevant to the latest version of better-auth by commenting on this issue.
  • If I do not hear back within 7 days, this issue will be automatically closed.

Thank you for your understanding and contribution!

<!-- gh-comment-id:3831312984 --> @dosubot[bot] commented on GitHub (Feb 1, 2026): Hi, @bossadizenith. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You requested adding a `lastUsed` boolean field to the Organization schema to track the most recently active organization per user. - This feature aims to enable automatic selection of the last used organization on sign-in, improving multi-organization user experience. - I support this enhancement and suggest outlining automatic updates, default behaviors, and handling edge cases like concurrent sessions. - You also recommended sharing any current workarounds using custom hooks to help guide native implementation. - This feature aligns with existing patterns such as the `lastLoginAt` field and would reduce manual client-side logic. **Next Steps:** - Please let me know if this feature request is still relevant to the latest version of better-auth by commenting on this issue. - If I do not hear back within 7 days, this issue will be automatically closed. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10337