I’m having an issue with the withAuthenticationRequired HOC. If I refresh a ProtectedRoute page it returns me to redirectUri page even if I declare the returnTo parameter.
The returnTo prop of the withAuthenticationRequired component works alongside the onRedirectCallback. If you don’t have an onRedirectCallback prop, then I don’t believe the prop will do anything.
If you use the onRedirectCallback example above, then you shouldn’t need to use the returnTo prop unless you want to redirect somewhere other then the link the user clicked. For example, if a user clicked on the protected /profile link in the app, you could either leave out the returnTo prop from withAuthenticationRequired to have them land on /profile after they log in, or you could include the returnTo prop to have them land somewhere else after login (e.g. /welcome-back).
I don’t understand the usage of onRedirectCallback exactly so I couldn’t get it to work. I would be glad if someone with a bit knowledge on this could explain further out.
By default this removes the code and state parameters from the url when you are redirected from the authorize page. It uses window.history but you might want to overwrite this if you are using a custom router, like react-router-dom
This function runs after authentication to handle the redirect callback.
You can find a full example of overriding the default behavior specifically for React Router in this article: