ReactJS: Okta Auth RestoreOriginalUri Function not Redirecting

I’ve been stumped on this issue for quite some time.

I am using Okta Authentication for my React SPA and everything is going well however the restoreOriginalUri function doesn’t actually route/redirect back to the Original URI on successful authentication.

package.json

    "@okta/okta-auth-js": "^5.6.0",
    "@okta/okta-react": "^6.2.0",
    "@okta/okta-signin-widget": "^5.8.1",

Code:

    <Security
      oktaAuth={oktaAuth}
      onAuthRequired={customAuthHandler}
      restoreOriginalUri={restoreOriginalUri} // not working
    >
      <Switch>
        <Provider store={store}>
          <Route exact path="/" component={Home} />
          <Route exact path="/reports" component={Reports} />
        </Provider>
      </Switch>
    </Security>
// restoreOriginalUri function

  const restoreOriginalUri = async (_oktaAuth, originalUri) => {
    console.log("restoring original uri...");
    history.replace(toRelativeUrl(originalUri, window.location.origin));
  };

Error message: enter image description here

I know for a fact that the authentication was successful as once I receive the error message and refresh the browser page, im able to navigate to my protected routes and see user identity via scopes without being forced to /login

Any ideas?

TIA

Answer

Try changing your restorOriginalUri const to the following:

const restoreOriginalUri = async (oktaAuth, originalUri) => {
  history.replace(toRelativeUrl(originalUri || '/', window.location.origin));
};