You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It should be redirecting to /foo/api/auth/login/ instead of /api/auth/login when baseURL is set in auth0 config.
The issue comes from the fact that req.pathname that is used inside the function doesn't contain Nextjs base url prefix. In your code you are first checking that in the ignorePaths the login url doesn't match the pathname. And then you use the same login url to redirect. So your logic will break either during the ignorePath matching or later when you redirect (depending on whether in your config you have the base url part of the login url or not). This was already mentioned here: #1118
Reproduction
create an auth0 instance with initAuth0(config) where you set the baseURL to your custom url such as localhost:3000/foo
use withMiddlewareAuthRequired inside your middleware.ts
Access your app, you will be redirected to /api/auth/login instead of /foo/api/auth/login/
Checklist
Description
withMiddlewareAuthRequired logic doesn't work for a custom auth0 instance with custom base URL set.
nextjs-auth0/src/helpers/with-middleware-auth-required.ts
Line 93 in 951a248
It should be redirecting to
/foo/api/auth/login/
instead of/api/auth/login
when baseURL is set in auth0 config.The issue comes from the fact that req.pathname that is used inside the function doesn't contain Nextjs base url prefix. In your code you are first checking that in the ignorePaths the login url doesn't match the pathname. And then you use the same login url to redirect. So your logic will break either during the ignorePath matching or later when you redirect (depending on whether in your config you have the base url part of the login url or not). This was already mentioned here: #1118
Reproduction
initAuth0(config)
where you set the baseURL to your custom url such as localhost:3000/foo/api/auth/login
instead of/foo/api/auth/login/
Additional context
Already discussed here: #1118
nextjs-auth0 version
3.5.0
Next.js version
13.4.12
Node.js version
18.17.1
The text was updated successfully, but these errors were encountered: