Using withPageAuthRequired() with the basePath configured in the next.config.js doesn't redirect the user to the expected page. HOC uses the router.asPath prop: https://github.com/auth0/nextjs-auth0/blob/main/src/frontend/with-page-auth-required.tsx#L76
basePath to /appwithPageAuthRequired/ instead of /appHere's a log of the router object from the withPageAuthRequired():
{
"pathname": "/",
"route": "/",
"query": {},
"asPath": "/",
"components": {
"/": {
"initial": true,
"props": {
"pageProps": {}
}
},
"/_app": {
"styleSheets": []
}
},
"isFallback": false,
"basePath": "/app",
"isReady": true,
"events": {}
}
Hi @synoptase - thanks for raising this
withPageAuthRequired should redirect you back to the page you we're trying to visit
Go to the protected page and login
What was the url of the protected page you were trying to visit when you got redirected to the login? Did it match the url of the page you were returned to after login?
When I use the withPageAuthRequired, it does not redirect me to the page I intended to visit. It redirects me to the home page always
What was the url of the protected page you were trying to visit when you got redirected to the login? Did it match the url of the page you were returned to after login?
I was trying to access the root /app of my nextjs app. The withPageAuthRequired wraps a <Home /> component, in pages/index.js. Browser is returned to / instead of /app.
Tried with another page in pages/profile.js. Browsing /app/profile logged out brings me back to /profile after logging in.
It really seems to be related to asPath (here) not containing the full url. basePath needs to be prepend.
Let me know if that's helpful enough!
That's helpful, thanks @synoptase!
@ifeanyiisitor - you seem to have a different problem, can you raise a separate issue, including steps to reproduce, what Next/Node version etc?
This is now fixed on v1.2.0