32
Views
6
Comments
How to log out user when user close the browser without logged off
Application Type
Reactive

Hi Everyone,

When user is login into the application and without logging off if user closes the browser then I want to logged out that user from the application. How can I achieve it in reactive application ?
Please share your thoughts.

Thanks,
Ajit Kurane.

2024-10-19 11-15-19
Sazid

Hi @Ajit Kurane -

You can implement this using JavaScript. Attached is an OML file that will automatically log you out whenever you close the browser. 

AutoLogout.oml
2025-04-17 05-42-16
Ajit Kurane

If we have multiple screens into the application then I need to use same code (function) on the each and every page ?

 

2025-04-17 05-42-16
Ajit Kurane

On the edge browser it is working but on chrome browser its not working as expected.

2024-10-19 11-15-19
Sazid


it’s likely due to Chrome’s restrictions on beforeunload behavior, which often blocks async requests like fetch calls due to security policies. 

Another approach is to implement a heartbeat (or periodic check) that updates the user’s status in local storage to "active" at regular intervals. When the browser is closed, this heartbeat stops, which the server can then detect as an indicator of inactivity. To find a balanced approach, we can consider user behavior and the duration they remain idle on the page. Using this approach allows us to end the session based on inactivity, though it won't immediately close session on browser close event. try adding following javascript to achieve this.

// Function to set user as active in localStorage every few seconds function setActiveStatus() {    localStorage.setItem('userStatus', 'active'); } // Set the active status every 5 seconds setInterval(setActiveStatus, 5000); // Clear the active status on beforeunload (when user closes the browser/tab) window.addEventListener("beforeunload", function () {    localStorage.removeItem('userStatus'); }); 

Best Wishes

S

2019-01-31 08-54-57
André Costa
Champion

One important aspect of this behavior is ensuring that the session doesn’t persist when the browser is closed. You can configure session timeout settings in the OutSystems environment.

  • Go to Service Center > Administration > Environment Configuration.
  • Under the Session Configuration section, reduce the session timeout (e.g., set it to 10 or 15 minutes). This will ensure that if the user does not perform any activity (including closing the browser), they will be logged out after a set time.


2025-04-17 05-42-16
Ajit Kurane

Hi Andre,

I appreciate your response,

We have set session time out as of 40 minutes but before that if user used application for 10 minutes and close the browser without logged of then when he come back again to browser to access the application then user is able to login without using credentials. We have to avoid this for security reason.

Note: We have configured SSO using azure ad and apply the conditional access policy for the same use case for only personal devices (Unmanaged device). But still user is able to login on personal device when he close the browser. 

Thanks.

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