1 year ago
#286622
Paolo Di Pietro
How to detect if a cookie has been deleted
I have a ReactJS 17.0.2
application that made use of a couple of cookies to check if a user is logged in.
I use import { useCookies } from 'react-cookie';
If the user is logged in, he/she can open another tab in the browser, and being automatically recognized. Just the same as you are logged in multiple google pages: you log in just once.
The opposite for me is not true.
When the user logs out on one of the n pages, the cookies are deleted and the user is logged out on that page/tab.
But, in the other tabs, the user remains logged in.
I would like to use some mechanism to trigger the other page that the cookie has been deleted, so that I can force a logout to the other pages too.
I don't know how, but I'd like to have some kind of listener
or hook
able to be activated when the cookie has been deleted.
A kind of publishing/subscribing
approach, applied to cookies ....
I found nothing. The only idea in my mind is to have a react timeout
and then check once a second if the cookie yet exists, but I'm not enthusiast of this approach.
Any suggestion will be welcome.
reactjs
react-hooks
react-cookie
0 Answers
Your Answer