+1 Agreed. simpler = better
So, I did a quick proof of concept (emphasis on quick).
1 - Add redirectTo
to PrivatePageLoader
in router.js
/* router.js*/
const PrivatePageLoader = ({
useAuth,
unauthenticatedRoute,
redirectTo,
children,
}) => {
const { loading, isAuthenticated } = useAuth()
if (loading) {
return null
}
if (isAuthenticated) {
return children
} else {
return (
<Redirect to={`${unauthenticatedRoute()}?redirectTo=${redirectTo}`} />
)
}
}
that’s some ugly-ish interpolation and not 100% sure it gets escaped
2 - in RouterImpl, privateRoutes:
React.cloneElement(route, {
private: true,
redirectTo: null,
unauthenticatedRedirect: unauthenticated,
})
3 - and pass the path to that loader
return (
<PrivatePageLoader
useAuth={useAuth}
unauthenticatedRoute={
namedRoutes[route.props.unauthenticatedRedirect]
}
redirectTo={route.props.path}
>
<Loaders />
</PrivatePageLoader>
4 - In your app, when invoking login (for Auth0)
const searchParams = new URLSearchParams(window.location.search)
await logIn({
appState: { targetUrl: searchParams.get('redirectTo') },
})
Have to do some testing, but the basic flow works.