404 on api/auth/session when using basePath
See original GitHub issueYour question
How to set the correct path for /api/auth/session in an app using a custom basePath, it seems like an explicit NEXTAUTH_URL is ignored?
What are you trying to do
I have a global login app at root, running on mysite.com
On successful login, this redirects to another app which sits on a subpath like mysite.com/custom-app/
This app has a custom basePath set in the next.config.js
basePath: '/custom-app',
Login is successful and navigation to the subpath works correctly, but when the session is checked for, it seems to ignore the NEXTAUTH_URL and just checks the session at the default mysite.com/api/auth/session ?
NEXTAUTH_URL=mysite.com/custom-app/api/auth/
If I remove the basePath, everything works correctly when testing between two apps; one running on localhost:8080 the other localhost:3000
Just wondering if I’m missing something, or if this is even possible yet?
Thanks
- Found the documentation helpful
- Found documentation but was incomplete
- Could not find relevant documentation
- Found the example project helpful
- Did not find the example project helpful
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
@callamwilliams This is really interesting and I don’t actually understand the problem here or why what you did worked.
Please fee free to leave this open for future investigation in case it hints at a bug or just a gap in the docs.
I think the problem could be solved with a
pages/_app.jsfile which sets this option for both client and server side renders, although it looks like this functionality is not documented.I’d be interested in knowing if this also worked, instead of using
next.config.jsto export the env var - although I think exporting the env var that is absolute fine too, and I can see why it resolves the issue with a custom base path (as the NextAuth.js “client” supports being run both browser and server side, and reads in default values for options from env vars if they are set).For anyone ending up here, I summed up a possible solution at #1713! Please go there and comment on what you think!