As per the documentation on Angular's $rootScope:
To receive notifications whenever $digest() is called, you can register a watchExpression function with $watch() without a listener.
While I'm not certain if $digest
gets triggered after every user action, it could be a good starting point.
For your information, here's how I handle User time-outs:
- Authenticate the user using a server-side API.
- Store the user in a cache via the API with sliding expiration and return a session token.
- Require a session token for each secured API end-point to fetch the user from the cache, resetting the expiration timer.
- If the user isn't found in the cache, return a custom 403 error indicating 'User Timeout', prompting client code to redirect the user back to the login page.
This approach should suffice for most Single Page Apps since nearly all user actions trigger state changes involving server requests. Although some minor actions may be missed, real-world use shows that this technique offers sufficient resolution for effectiveness.