Mobile app version of vmapp.org
Login or Join
Berumen354

: How to detect the server has logged out the user from the client side? For performance reasons I'm setting some user info in the local storage of the client/navigator when he logs in. It allows

@Berumen354

Posted in: #Authentication #Logging #Session

For performance reasons I'm setting some user info in the local storage of the client/navigator when he logs in.

It allows me to tune the pages appearance (show/hide menus, display the name of the user,etc...) whether the user is logged or not.

This works perfectly as long as there is no session desynchronization between the client and the server. For instance if the server session ids are flushed, the client has no way to guess it. As a consequence, the user cannot access the "private" content (redirection to the home page in my case) although the page appearance looks like the user is still connected/identified.

A first solution that came to me is to detect the redirection on the client side (javascript), erase the local information regarding the user and modify the website appearance to correspond to a disconnected user.

My question is

Is there another smarter way to detect session id invalidation from the client side?

Subsidiary question

Are there side effects I'm missing with the "page redirection" detection solution?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Berumen354

1 Comments

Sorted by latest first Latest Oldest Best

 

@Berumen354

The solution I decided to go for:

Client:
On redirection detection (3xx HTTP response) the client is sending a request to the server to check specifically if the user is connected or no (the redirection can be due to another reason than "unidentified" user).

Server:
The server answers this request that is allowed for any user (identified or not) and hence not triggering a redirection.

Client:
On answer reception the client decides to display the "identified" or "unidentified" interface of the page. If not identified it erases the user data from local storage.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme