Question on Auth0Provider, redirectUri, onRedirectCallBack

Hi Auth0 Team,

I have successfully done an integration between auth0 and my react app. Posting code snippet here.

const onRedirectCallback = (appState) => {
  history.push(appState?.returnTo && appState.returnTo);
}

const providerConfig = {
  domain: DOMAIN, clientId: CLIENT_ID, audience: AUDIENCE, redirectUri: window.location.origin,
  onRedirectCallback
}

ReactDOM.render(
  <Auth0Provider
    {...providerConfig}
  >
    <App />
  </Auth0Provider>,
  document.getElementById('root')
);

From what I understand, redirectUri prop is mandatory. I had to introduce onRedirectCallBack as post redirecting from auth0, I wanted to redirect to another client side react route using the history object.

So right now whenever redirection from auth0 happens, it executes the useEffect() hook twice. The useEffect() has logic to persist some data in db through API calls. This API end point is also invoked twice. Luckily these calls are idempotent. However, I would still like to avoid mutliple API calls happening. Need your expert advice here.

Cheers!!
Prasad

appreciate some inputs on this.