Redirect after Logout in React SPA

Last Updated: Aug 20, 2024

Overview

There is an SPA in React where the following logout function is used:

logout({
  logoutParams: {
        returnTo: window.location.origin
  }
})

There are also two allowed Logout URLs configured:

The issue seems to be that no matter what environment is used, when doing the redirect, it is not redirecting to “window.location.origin”, but is redirecting to the first URL in the list.

Applies To

  • Logout Redirect
  • React SPA

Solution

Using the following logout should solve the issue:

const logoutWithRedirect = () =>
    logout({
      returnTo: window.location.origin,
    });