Add a "lastLoginAt" field to users #1805

Closed
opened 2026-03-13 09:04:45 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @maelp on GitHub (Aug 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

It's quite common in apps, or at least for the admins, to want to know the last time some user logged-in, to see which accounts are fresh or stale, etc

Describe the solution you'd like

Add a default (or optional) lastLoginAt field

Describe alternatives you've considered

Implement it myself with an additionalField and a hook

Additional context

No response

Originally created by @maelp on GitHub (Aug 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. It's quite common in apps, or at least for the admins, to want to know the last time some user logged-in, to see which accounts are fresh or stale, etc ### Describe the solution you'd like Add a default (or optional) lastLoginAt field ### Describe alternatives you've considered Implement it myself with an additionalField and a hook ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:04:45 -05:00
Author
Owner

@0xEbrahim commented on GitHub (Aug 30, 2025):

I want to work on this

@0xEbrahim commented on GitHub (Aug 30, 2025): I want to work on this
Author
Owner

@ping-maxwell commented on GitHub (Aug 31, 2025):

You can infer the last time at which they logged in based on the most recently created session for a given user

@ping-maxwell commented on GitHub (Aug 31, 2025): You can infer the last time at which they logged in based on the most recently created session for a given user
Author
Owner

@maelp commented on GitHub (Aug 31, 2025):

@ping-maxwell sure, but I guess it means a lot of joins to get the info when displaying the user, while it might be convenient to store it on the user itself?

@maelp commented on GitHub (Aug 31, 2025): @ping-maxwell sure, but I guess it means a lot of joins to get the info when displaying the user, while it might be convenient to store it on the user itself?
Author
Owner

@ping-maxwell commented on GitHub (Aug 31, 2025):

In most cases where a lastLoginAt value would be displayed in the UI, the user would already be logged in. That means the front-end likely already has the user’s information, so joins aren’t needed. Retrieving the most recent session byuserId should only require a single database query.

Adding a new field to the user table introduces significantly more complexity, since it impacts every Better-Auth user. That would be a major breaking change for something that can already be achieved with a straightforward DB call.

For these reasons, I believe adding lastLoginAt is unnecessary.

@ping-maxwell commented on GitHub (Aug 31, 2025): In most cases where a `lastLoginAt` value would be displayed in the UI, the user would already be logged in. That means the front-end likely already has the user’s information, so joins aren’t needed. Retrieving the most recent session by`userId` should only require a single database query. Adding a new field to the user table introduces significantly more complexity, since it impacts every Better-Auth user. That would be a major breaking change for something that can already be achieved with a straightforward DB call. For these reasons, I believe adding `lastLoginAt` is unnecessary.
Author
Owner

@maelp commented on GitHub (Aug 31, 2025):

@ping-maxwell but that's what I'm saying: the feature here is not for the user himself to see what time he last logged in (he doesn't care)

the feature is for the admin to have the list of last login time for all accounts (to detect stale accounts that haven't logged in for a while, do audits, etc)

@maelp commented on GitHub (Aug 31, 2025): @ping-maxwell but that's what I'm saying: the feature here is **not** for the user himself to see what time he last logged in (he doesn't care) the feature is for the **admin** to have the list of last login time for all accounts (to detect stale accounts that haven't logged in for a while, do audits, etc)
Author
Owner

@maelp commented on GitHub (Aug 31, 2025):

It could also be something optional like adding a "lastLoginAtPlugin" so it doesn't change anything for existing users

@maelp commented on GitHub (Aug 31, 2025): It could also be something optional like adding a "lastLoginAtPlugin" so it doesn't change anything for existing users
Author
Owner

@ping-maxwell commented on GitHub (Aug 31, 2025):

I think it makes most sense to update the admin plugin, for whichever endpoint that relates to this to include a lastLoginAt in the result. (Most likely the listUsers endpoint, but it's up for discussion)
Adding that field to the schema has a lot more hidden complexities than you might think

@ping-maxwell commented on GitHub (Aug 31, 2025): I think it makes most sense to update the admin plugin, for whichever endpoint that relates to this to include a `lastLoginAt` in the result. (Most likely the `listUsers` endpoint, but it's up for discussion) Adding that field to the schema has a lot more hidden complexities than you might think
Author
Owner

@maelp commented on GitHub (Aug 31, 2025):

Then indeed it could be donne on the admin plugin, it's a good idea. Yes, I'm sure it is complicated, that's why I wanted it to be included "by default" so we don't have to manually implement it each time we need it. I think the complication is mostly because of the variety of ways we can connect? eg either from /sign-in/email, or from oauth callbacks, etc?

@maelp commented on GitHub (Aug 31, 2025): Then indeed it could be donne on the admin plugin, it's a good idea. Yes, I'm sure it is complicated, that's why I wanted it to be included "by default" so we don't have to manually implement it each time we need it. I think the complication is mostly because of the variety of ways we can connect? eg either from /sign-in/email, or from oauth callbacks, etc?
Author
Owner

@himself65 commented on GitHub (Sep 18, 2025):

I think you can retrieve the last login date from the session database

@himself65 commented on GitHub (Sep 18, 2025): I think you can retrieve the last login date from the session database
Author
Owner

@ptts commented on GitHub (Oct 18, 2025):

I think you can retrieve the last login date from the session database

Only while the user is logged in, though — once they sign out, their session record is deleted. If that was their only active session, the derived “last login at” info would no longer exists; otherwise, it would fall back to the timestamp of their previous (still active) session.

@ptts commented on GitHub (Oct 18, 2025): > I think you can retrieve the last login date from the session database Only while the user is logged in, though — once they sign out, their session record is deleted. If that was their only active session, the derived “last login at” info would no longer exists; otherwise, it would fall back to the timestamp of their previous (still active) session.
Author
Owner

@dosubot[bot] commented on GitHub (Jan 17, 2026):

Hi, @maelp. 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 "lastLoginAt" field to user data for admins to track account activity.
  • The maintainer suggested inferring last login info from session data without schema changes, proposing enhancements to the admin plugin instead.
  • Other commenters pointed out that session data might be incomplete since sessions are deleted on sign-out.
  • The issue remains unresolved with no implemented solution yet.

Next Steps:

  • Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue.
  • If I don’t hear back within 7 days, I will automatically close the issue.

Thanks for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jan 17, 2026): Hi, @maelp. 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 "lastLoginAt" field to user data for admins to track account activity. - The maintainer suggested inferring last login info from session data without schema changes, proposing enhancements to the admin plugin instead. - Other commenters pointed out that session data might be incomplete since sessions are deleted on sign-out. - The issue remains unresolved with no implemented solution yet. **Next Steps:** - Please let me know if this feature is still relevant to the latest version of better-auth by commenting on this issue. - If I don’t hear back within 7 days, I will automatically close the issue. Thanks 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#1805