When navigation to a certain page, I want to check if the user is logged in and their session token is still active.
If the session token does not exist, or it has expired, I want the user to be re-directed to a "login" page.
I have read responses to other similar questions that say that the way to check that a user is logged in is to look at the localStorage variable "userSessionToken" to see if it is populated.
However, this solution is not suitable for the following scenario:
user logs in (localStorage "userSessionToken" = [token value] )
user sits idle for over 120 minutes
current session token is now expired, however, the localStorage variable is still populated with the same [token value]
when user now tries to perform a PUT request (which requires an active token), it will fail.
I want to avoid this above scenario by performing a check on whether the current token I have stored in my localStorage variable is still active or not before I try perform the PUT request.
How is the best (most efficient) way for me to do this?
One thought I had was to simply perform a 'dummy' List or Query service, with the only request being the session token, and if this returns a SUCCESS response, then the token is active (and if it returns an ERROR it has expired), however I assume this may also return a lot of other data and even though I'm not mapping any of it, it still may take some time and cause data usage to be high.
I also could not see a way to do a simple LIST of QUERY service on the Users data collection. Is this possible?
Can you provide a suggestion as to the best (most efficient) way to perform this check?