Rank 1: Thread
Hello, I'm kinda new here and I'm curious.. is there any easy and BETTER way how to check if session was deleted?
I'll give an example what I want to do:
I connected 2 browsers into 1 account
I deleted session one of them
I want to check deleted session and (instant?) log out user
I did checking if session exist every minute (authContext) - it's working and logout user without session, but I'm not sure if it's the best way to make it, every 60s pinging API for response.
useEffect(() => {
const cookieFallback = localStorage.getItem('cookieFallback')
if (
cookieFallback === '[]' ||
cookieFallback === null ||
cookieFallback === undefined
) {
navigate('/sign-in')
}
checkAuthUser()
if (isAuthenticated) {
const interval = setInterval(() => {
getCurrentSession().then(() => {
setUser(INITIAL_USER)
setIsAuthenticated(false)
navigate('/sign-in')
console.log('error')
})
}, 60000)
return () => clearInterval(interval)
}
}, [isAuthenticated])