As a security feature of an app I’m building, I want to create a ‘Session’ data type as described below.
Session
Session-Started: Date and Time
Session-Ended: Date and Time
For Session-Started, I can easily Create a new ‘Session’ thing and insert Current Date and Time whenever a user logs in.
For Session-Ended, I can update Current User’s Session: First Item’s Session-Ended whenever a user logs out of my app.
However, sometimes the app can automatically log a user out randomly without any trigger. In this case, is there a reliable way to update a User’s Session’s First Item’s Session-Ended field without trigger from a user (e.g. without clicking log out button etc…)?
Pretty sure you can’t reliably check that someone has logged out without something like a websocket.
Possible methods include what you’re doing to track logins and then to also update some date field when they visit a page or do some action.
If you are already creating some form of logging (eg. when user comments or generates a report) you can use that data to track user activity. Then just define a set amount of time to mark users as inactive. Inactive doesn’t have to be an actual state, just apply that as an expression for whatever conditions you need.