Reputation: 374
I want to remove the user Authentication when the application has been loaded in multiple tabs. Once all the tabs that had the application loaded are closed or the entire browser is closed, I want to remove the token stored in local storage. When a user again opens a new tab and tries to enter the application, it should redirect to the login page. How can this be achieved in react, like how to detect that all tabs that have that application loaded closed?
Note -- I want to remove the token and display the login page only when all the tabs are closed or the browser is closed.
For an Instance, If the application has been loaded in 5 tabs, on the closing of all 5 tabs only I need to remove the token.
Is it possible to use a Broadcast channel to achieve this? but I am not sure how to implement them
Upvotes: 1
Views: 1988
Reputation: 130
Did you try this way?
openedTab === 0
then clear it in unload eventUpvotes: 1