I checked the default Users table in the ABP system, but I couldn’t find any field related to LastLogin.
Is there any built-in support in ABP to track the user's last login time? If not, what’s the recommended way to implement and maintain this value?
Looking for guidance on how to properly achieve this.
Thanks!
3 Answer(s)
-
0
ABP Framework does not provide a built-in LastLogin field in the default Users table (AbpUsers). However, ABP does offer a way to track user login events through the Security Log feature, which records login and logout activities.
Recommended Approach
Use Security Logs to Track Logins
- ABP automatically logs user login events in the Security Log. You can query the security logs to get the last login time for a user.
- The relevant table is usually
AbpSecurityLogs
(or similar, depending on your version).
Custom LastLogin Property (Recommended for Direct Access)
- If you want a direct LastLogin field on the user entity, you can extend the IdentityUser entity to add a custom property.
- Update this property whenever a user successfully logs in (e.g., in a custom login event handler or by overriding the login logic).
Example:
// 1. Add property to user entity (see ABP docs for entity extension) ObjectExtensionManager.Instance .MapEfCoreProperty<IdentityUser, DateTime?>("LastLoginTime"); // 2. Update LastLoginTime after successful login user.SetProperty("LastLoginTime", DateTime.UtcNow);
- Don't forget to add a migration and update the database.
SignalR/Active User Tracking (Optional)
- For real-time tracking of currently logged-in users, you can use SignalR and manage a list of active users in memory or cache, as shown in the ABP support example.
Summary
- There is no built-in LastLogin field, but you can use Security Logs or extend the user entity to add and maintain this value yourself.
Sources:
- ABP Database Tables
- How to Add Custom Properties to the User Entity
- ABP Support: Get All logged in users
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
For Custom LastLogin Property, where exactly should I update this value after a user logs in? Should I do it by handling some login event, or do I need to override the login method somewhere?
If you have a small code example or can point me to the best place to add this logic, that would be great.
-
0
[smwasimraja@gmail.com] said: For Custom LastLogin Property, where exactly should I update this value after a user logs in? Should I do it by handling some login event, or do I need to override the login method somewhere?
If you have a small code example or can point me to the best place to add this logic, that would be great.
Hi, maybe you can write event handler for OpenIddict Events and for each signin or signout find the current user and update the related custom property. I have an article for OpenIddict Events, which you can check at https://abp.io/community/articles/customizing-authentication-flow-with-openiddict-events-in-abp-framework-e59qfi9n#gsc.tab=0
In this article, I've created a signout event handler, which is triggered on every signout. You need to do it for the signin event, and you can use
OpenIddictServerEvents.ProcessSignOutContext
for that.Please check the article and let me know if you need any help.
Regards.