Ussie redirecting to base URL after each successful login with @auth0/auth0-react


I have been struggling when I get successful login the user is being redirected to the accurate page but after a second it is redirected to the base URL. I have found similar problems on the forum but still did not manage to figure out mine. In several posts I saw that I need to use appState in the loginWithRedirect like :

       appState: {target: pathname}

But still did not work. In my case I have the following auth0 configuration:

const onRedirectCallback = (appState: AppState) => {
        navigate(appState?.returnTo || appState?.target || window.location.pathname);

    return (

The reason I have appState target and returnTo is because I have other component which is admin dashboard and it is protected by withAuthenticationRequired HOC and where I still have login prompt if the user is not authenticated and I still need to redirect after successful login.

const ProtectedRoute = ({component}: Props) => {
    const {pathname} = useContext(RedirectContext);

    const Component = withAuthenticationRequired(component, {
        returnTo: pathname,
        onRedirecting: () => <div>Redirecting you to login</div>
    return <Component  />

export default ProtectedRoute;

In the both sections after a successful login it is accurately redirected then I get a redirection to the base URL.
Would appreciate you help!