-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
404 on api/auth/session when using basePath #689
Comments
Through some trial and error, I discovered that by setting the env again in the module.exports = {
env: {
NEXTAUTH_URL: process.env.NEXTAUTH_URL
}
} |
related to #587 @iaincollins That seems to be an FAQ and should be documented, and or can we change it to align with https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser? What means |
It is best to set it as an environment variable in The variable is required to support server side rendering flows (on both pages and in API routes) across an app. The environment variable is generally not needed in client side flows as they can access the client from a relative URLs (e.g. when running client site it just uses relative URLs like Happy to make this clearer in the docs! They could be more explicit about this. |
@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 import { Provider } from 'next-auth/client'
export default function App ({ Component, pageProps }) => {
return (
<Provider session={pageProps.session} options={{ basePath: `/custom-app/api/auth` }}>
<Component {...pageProps} />
</Provider>
)
} I'd be interested in knowing if this also worked, instead of using |
@iaincollins I'm not sure but the environment is actually required to use |
@iaincollins thanks for your answer in previous comment. But what is actual status of this case? It's a bug? I'm finding a solution for apps with basePath and i guess, way with manual injecting basePath like this: import { Provider } from 'next-auth/client'
const {basePath} = getConfig();
export default function App ({ Component, pageProps }) => {
return (
<Provider session={pageProps.session} options={{ basePath: `/${basePath}/api/auth` }}>
<Component {...pageProps} />
</Provider>
)
} Is not the best way, because next-auth can use some integration with next.js and provide more clear development experience :) |
For anyone ending up here, I summed up a possible solution at #1713! Please go there and comment on what you think! |
Same problem if you have 2 "api" directories. One in root of project, and one in "pages" directory. |
Removing the |
spent quite a time before trying this approach and it worked. thank you @aerinkim ! |
Your question
How to set the correct path for
/api/auth/session
in an app using a custom basePath, it seems like an explicitNEXTAUTH_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
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
?If I remove the basePath, everything works correctly when testing between two apps; one running on
localhost:8080
the otherlocalhost:3000
Just wondering if I'm missing something, or if this is even possible yet?
Thanks
The text was updated successfully, but these errors were encountered: