We are trying to determine logged-in status of our users as part of an automated lead-routing process (we only want to route to logged-in users), but we are seeing some inconsistencies.
We currently have a scheduled apex job running every 15 minutes executing this query: SELECT Id, UsersId FROM AuthSession WHERE SessionType = 'UI'
If a record exists we are assuming that the user is logged in.
However, it seems that some -but not all- AuthSession entries are never deleted, even when the user is no longer logged in, causing them to appear logged-in according to our process.
What could be causing this?
Could it be because some users are actively logging out using the logout button while others aren't? (In order to try and remedy this, we have now turned on the 'Force logout on session timeout' in the Session Settings).
We were wondering if we could use the isCurrent field on the AuthSession object, but it is false for all users at all times.
FYI, we are using SSO.