31
Views
5
Comments
Automatically logout in duplicate tab ana new tab
Question
Application Type
Reactive

My scenario for banking security :
Once I log in by entering the username and password in one browser tab,
then if I duplicate the browser or open the application again in a new tab,
the login screen should appear again login screen and ask credential again.

Please modify my oml.
Thankyou

Browser_Duplicate.oml
UserImage.jpg
Aravind I

Hi Joey,

For banking-style security where each tab requires its own login, you can use 'sessionStorage', which is unique per browser tab. 

Please follow these simple steps to achieve it:

1. On successful login, add the below js to ensure the authentication

                  sessionStorage.setItem("IsAuthenticated", "true");

2.Add a Onready to the layout of the screen :

                  var isAuth = sessionStorage.getItem("IsAuthenticated");

                  $public.ReturnValue = isAuth === "true";

3. Clear the session while you logout:

                sessionStorage.clear();


I hope Its helpful.






2024-07-12 05-57-50
Gourav Shrivastava
Champion

Hello @Joey Olive  

Let me share a step process you can follow 

First:- 

  • On login, set a unique key like:-
  • if (!sessionStorage.getItem("TabToken")) {
  •   sessionStorage.setItem("TabToken", Date.now().toString() + Math.random().toString());
  • }

  • It will help you to generate a unique key, and then after login, you can insert that into your DB as a TabUnique key


Second:- 

  • On every InReady or OnInitialize of protected screens, you get the TabToken like 
  • sessionStorage.getItem('TabToken'); // From js
  • and compare this to your DB value, if it matches then go, otherwise match then redirect to the login screen

Third:- 

Set TabUnique to NULL in DB on logout. 


Note:- for setting sessionStorage use setItem, and for getting sessionStorage use getItem with your key name 



Thanks 

Regards,

Gourav Shrivastava


2019-01-07 16-04-16
Siya
 
MVP

@Joey Olive : I understand that you want the user to log in again from the new tab. What about the previous tab? Do you expect the same user to be logged in from two different tabs?

2025-01-25 07-56-04
Joey Olive

Hello @Siya :

1. I want when I login on the first tab, it should open. But it should not open on the second tab, the login screen should appear again. 
2. The first tab should already remain open even after refreshing.

2022-07-24 08-50-37
Gokula Kannan P

Hi @Joey Olive,

It’s a valid solution as the fellow members suggested. But you have to keep in mind one more constraint:

if you duplicate the tab, even sessionStorage will be cloned, so it won’t help you to force logout in that case.

To handle this, after creating the tabToken as mentioned above, you should also store it in a window property like this below

window._tabToken = "<token value>";

When a tab is duplicated, window._tabToken will be null or undefined, since memory-only variables don’t carry over.

You can use this to verify that the current tab is the original and not a duplicate by comparing window._tabToken with the value stored in sessionStorage.

Also, if you’re using OutSystems Login (which relies on cookies), logging out in one tab will log out all tabs — because cookies are shared across tabs.

Hope this helps!

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