31
Views
3
Comments
Solved
How to know session has expired in Reactive web application

Hi All

I want to know if the session has expired in Reactive web application. I know if the session expires it takes me to OnException event but for normal login also it takes me to OnException event.

i want to implement a logic only on session expire in OnException event not for normal login

please advise

Thanks

Kumar V

2024-09-14 05-42-00
Ozan Can Çalı
Champion
Solution

Hi Kumar,

I don't think it's possible to easily understand when the session is expired. We basically use GetUserId() to understand if there is a user session or not. So if there is no user session, we redirect to Login screen by default.

What I can suggest is that you build a check mechanism with JS that checks every X seconds if the user still has a session or not, as soon as the user opens a page that needs a session. If the check returns that there is no user session anymore, you set a client variable such as "IsSessionExpired" to True. To check if there is still a session, you can maybe do an operation that would only return data if there is a session. If no data is returned, it means that the session is no more.

This way, in the OnException flow in the SecurityException handler, you can add an extra check to see if this IsSessionExpired variable is True or not. If it's the first time that user is opening the app and needs to log in, this variable will be False, so the user will be redirected to the Login page as before. But if it's True, you can implement your specific logic.

UserImage.jpg
saravanakumar v

Hi Ozan

I have a doubt. does the client variables get cleared on logout/session expiry ?

Thanks

Kumar V

2024-09-14 05-42-00
Ozan Can Çalı
Champion

Hi Kumar, you're right the client variable will be cleared on logout/session expiry.
In that case I suggest that you keep that IsSessionExpired =True in a persistent storage such as local storage or in the database, together with the UserId. But the rest of the logic can stay the same. 
What we're trying to achieve is basically to keep somewhere that the user has logged in recently, but their session is expired due to inactivity etc. If it's the first time that the user is visiting in a long time, this variable would be empty/False.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.