Logout always redirects to first url from Allowed Logout URLs

Hi there, I know it’s been a while since this was posted but I’ll provide my solution just in case someone else has the issue. I’ve used older versions of Auth0 before and not encountered this so I can only assume I was using older versions of the library.

Firstly, logoutParams doesn’t exist on the Auth0Provider, but it is an optional argument in auth0’s logout function.

I also found that the redirect_uri: window.location.origin within the authorizationParams object was seemingly being ignored. Originally, this would redirect to the correct URL in the “Allowed Logout URLs”, not just the first one.

Old:

const { logout } = useAuth0();
<Button onClick={() => logout()}>Log out</Button>

If you provide the information in the logoutParams option of the logout function, you’ll get the desired behaviour.

New:

const { logout } = useAuth0();
<Button 
  onClick={() =>
    logout({
      logoutParams: {
        returnTo: window.location.origin
      }
    })
  }
>
Log out
</Button>

Hope this helps!

4 Likes