Sync auth state between multiple applications (SPA & Chrome Extension)

yes, that’s also browser extension specific, as you can’t forward to the auth0 logout page. What I did to solve this issue, is just creating a little “enhanced logout function” that is calling the auth0 endpoint and clearing the session:

const EnhancedLogout = () => {
        logout({federated: true, returnTo: window.location.origin})
        // we need to manually clear the session .. the normal logout with forwarding is not working
        // for a browser extension
        fetch('https://'+process.env.AUTH0_DOMAIN+'/v2/logout?federated=true&client_id='+process.env.AUTH0_CLIENT_ID,{
          credentials: 'include',
          mode: 'no-cors'
        }).catch()
      }

Furthermore, in the auth0-react helper:

const logout = (options?: LogoutOptions) => {
    auth0Client!.logout(options)
    setIsAuthenticated(false)
  }

I’m immediately setting “setIsAuthenticated” to false, so that the user gets a good feedback.

2 Likes