Skip to content
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

Next basePath not handled on signin page #9425

Closed
marcoreni opened this issue Dec 20, 2023 · 9 comments
Closed

Next basePath not handled on signin page #9425

marcoreni opened this issue Dec 20, 2023 · 9 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@marcoreni
Copy link

Environment

System:
OS: macOS 14.2
CPU: (10) arm64 Apple M1 Pro
Memory: 149.20 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/Library/Caches/fnm_multishells/2567_1703023890015/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 10.2.3 - ~/Library/Caches/fnm_multishells/2567_1703023890015/bin/npm
pnpm: 8.12.1 - /opt/homebrew/bin/pnpm
bun: 0.5.8 - ~/.bun/bin/bun
Browsers:
Chrome: 120.0.6099.109
Safari: 17.2
npmPackages:
next: 14.0.4 => 14.0.4
next-auth: 5.0.0-beta.4 => 5.0.0-beta.4
react: 18.2.0 => 18.2.0

Reproduction URL

https://github.com/marcoreni/next-auth-repro-base-path

Describe the issue

My application has a basePath configured on "next" side. However, this is not fully handled properly on Next.

Session call work, redirection to signin page works, but the form action does not contain the

How to reproduce

  1. Configure a basePath inside next.config.js
  2. Configure the base path according to Next-Auth configuration (both NEXTAUTH_URL and basePath inside session provider)
  3. Open the project and click on Signin. You will be redirected to /api/auth/signin instead of /{basePath}/api/auth/signin.

(NOTE: the repro repository has been configured with a base path of "/foo". If you open http://localhost:3000/foo/middleware-example , you will be redirected on the login page, and clicking on the Github button will yield the problem)

Expected behavior

The form action URL should include the basePath.

@marcoreni marcoreni added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Dec 20, 2023
@jenewland1999
Copy link

Behaviour is still present in in Next.js v14.1 and next-auth v5 beta.5

@balazsorban44 balazsorban44 assigned ndom91 and unassigned ndom91 Jan 25, 2024
@balazsorban44
Copy link
Member

The next.config.js basePath cannot be propagated to NextAuth.js, so you need to manually add this as a prop to SessionProvider and to the NextAuthConfig.

@jenewland1999
Copy link

jenewland1999 commented Jan 25, 2024

@balazsorban44 According to the types being shipped in beta.5, basePath is not a valid option for NextAuthConfig. Also, if we use App Router, do we still need SessionProvider to wrap the entire app in the Root Layout? The upgrade guide suggests it doesn't, but I thought I'd ask at least. Furthermore, does the AUTH_URL env var need the basePath on it too (i.e. http://localhost:3000/foo)

image

@balazsorban44
Copy link
Member

Not shipped yet but it's here

config.basePath ??= "/api/auth"

SessionProvider will likely be not needed in App Router at all. We'll document this soon.

@jenewland1999
Copy link

Okay, thank you. I'll keep an eye on the releases page for now. 😄

@hscstudio
Copy link

So, now, can I do for it? I must run Next 14 App router on sub directory, but fail becaus auth 5 not yet supported..

http://localhost:3000/admin

I have add in SessionProvider

and

in AuthConfig

basePath:"/admin/api/auth"

but still error

@neoplastic
Copy link

@hscstudio I'm getting this same problem. Mine says in the logs
Cannot parse action at /api/auth/callback/nodemailer. Read more at https://errors.authjs.dev#unknownaction

@mirkahromi
Copy link

The next.config.js basePath cannot be propagated to NextAuth.js, so you need to manually add this as a prop to SessionProvider and to the NextAuthConfig.

Could you please elaborate a bit more how to set them up?

@nktnet1
Copy link

nktnet1 commented Nov 13, 2024

Collection of workarounds I've found:

  1. k3k8's solution
  2. ThanhHuuVu's solution
  3. andreynovikov's solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

8 participants