-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
the new useSession should use basePath settings for redirect #2316
Comments
So I'm fairly sure that this is also the current behavior, and that this issue is a duplicate of #1713, but at least related. UPDATE, on second read, I now know what you mean. You could easily use a custom `onUnauthenticated method though, if you saw rest of the PR. UPDATE2: We could probably utilize the |
I tested this out at my local machine. Let me know if I got something wrong, but here is what I understood: Assuming OP's description, this is sort of his folder structure: .
├── pages
│ ├── api
│ │ └── v1
│ │ ├── auth
│ │ │ └── [...nextauth].js
... other files and, he has set NEXTAUTH_URL=http://localhost:3000/api/v1 Now, with the way environment variables work, they won't be available client-side. If we take a look at the // Default values
const defaultHost = 'http://localhost:3000'
const defaultPath = '/api/auth'
if (!url) { url = `${defaultHost}${defaultPath}` } This right here is the problem. The hardcoded values should instead refer to the environment variable. But, since we do not have an environment variable access client-side, initially I thought
but this will break other parts of the application that rely on // We should always update if we don't have a client session yet
// or if there are events from other tabs/windows
if (storageEvent || __NEXTAUTH._session === undefined) {
__NEXTAUTH._lastSync = _now()
__NEXTAUTH._session = await getSession({
broadcast: !storageEvent,
})
setSession(__NEXTAUTH._session)
return
} So, the only real solutions would be:
Then, |
@mahieyin-rahmun, Sorry, I also missed in my description that I'm also setting I do agree that the "best" way of fixing this is to use |
I see. Even if you do that, as you pointed out, the current signin flow doesn't make use of the passed prop. Whether we go with solution 1 or 2, a refactor of the core client module is needed to make this work 😅 I believe if the core team agrees to introduce the new environment variable, the necessary refactors could be done. But, that would be something that should only go live with v4, as it would be a big breaking change, and several parts of the documentation will require review and hence change. |
Are there any updates on this? I believe I'm running into the same issue and am very blocked. I need my next-auth REST calls to use /app/api/auth instead of /api/auth. I have the basePath and baseUrl set in the SessionProvider. I also have the NEXTAUTH_URL set properly. But the redirects after login are still going to: /api/auth. |
@lenzi-erickson Possibly setting the |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Description 🐜
Follow-up for #2236 , as I was browsing the code changes I noticed that the redirect in
useSession
doesn't use the basePath settings that are set fromNEXTAUTH_URL
. We use a slightly different url paths in our project (/api/v1/auth/...
) so we rely on everything being parsed from fromNEXTAUTH_URL
EDIT: I'm also providing
basePath
to theSessionProvider
to match theNEXTAUTH_URL
Is this a bug in your own project?
No
How to reproduce ☕️
NEXTAUTH_URL
to have a different path to usual: eg:NEXTAUTH_URL=http://localhost:3000/api/v1/auth
Screenshots / Logs 📽
No response
Environment 🖥
next-auth@next
Contributing 🙌🏽
No, I am afraid I cannot help regarding this
The text was updated successfully, but these errors were encountered: