Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
Clear tokens in Local Storage when all tabs or Browser is closed in React

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Did you try this way?

  1. Count every tab open and save it to localStorage
  2. Handle event unload and update localStorage if openedTab === 0 then clear it in unload event
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!