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

Sign In page Buttons don't respect basePath when clicked #10009

Open
jenewland1999 opened this issue Feb 12, 2024 · 5 comments
Open

Sign In page Buttons don't respect basePath when clicked #10009

jenewland1999 opened this issue Feb 12, 2024 · 5 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@jenewland1999
Copy link

Environment

System:
OS: macOS 14.3.1
CPU: (8) arm64 Apple M1 Pro
Memory: 1.34 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.11.0 - ~/Library/Caches/fnm_multishells/47131_1707656901311/bin/node
Yarn: 1.22.21 - ~/Library/Caches/fnm_multishells/47131_1707656901311/bin/yarn
npm: 10.2.4 - ~/Library/Caches/fnm_multishells/47131_1707656901311/bin/npm
pnpm: 8.15.1 - ~/Library/pnpm/pnpm
bun: 1.0.26 - ~/.bun/bin/bun
Browsers:
Chrome: 121.0.6167.160
Safari: 17.3.1
npmPackages:
next: ^14.1.0 => 14.1.0
next-auth: 5.0.0-beta.9 => 5.0.0-beta.9
react: ^18.2.0 => 18.2.0

Reproduction URL

https://github.com/jenewland1999/next-auth-bug-repro

Describe the issue

Using the basePath option in Next.js does not currently work with the latest beta of NextAuth.js.

This is because when you're taken to the sign in or sign out page, clicking the button will send you to a URL that does not include the basePath. Setting the basePath option in NextAuth.js does not affect this.

Furthermore, the use of the AUTH_URL environment variable causes all the endpoints NextAuth.js creates to return the following error message:

"Error: This action with HTTP GET is not supported."

How to reproduce

  1. Clone the example
  2. Create a .env file with the AUTH_SECRET and your Provider secrets of choice (in my case that's Azure AD)
  3. If you've chosen a different provider, configure accordingly in the auth.ts file
  4. Start the dev server and navigate to http://localhost:3000/foo
  5. Click the login button

You will now be on a 404 page.

Expected behavior

The basePath is taken into account when clicking the sign in or sign out button on the inbuilt pages. And specifying AUTH_URL also doesn't return the above error message.

@jenewland1999 jenewland1999 added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Feb 12, 2024
Joshwantt added a commit to Joshwantt/jsohdev-site that referenced this issue Feb 13, 2024
next-auth beta 9 looks to introduce a bug for all auth routes when a AUTH_URL env is supplied

nextauthjs/next-auth#10009
@jenewland1999
Copy link
Author

Still an issue with beta.11

@sx-bpreck
Copy link

I am facing the same issue on version 4.24.7

@TomWonder
Copy link

I am facing the same issue on version 4.24.7

Same here

@TomWonder
Copy link

TomWonder commented May 10, 2024

Same issue also on v5 beta.17

@TomWonder
Copy link

TomWonder commented May 10, 2024

Workaround here:

  1. Switch back to 4.24.7
  2. Use SessionProvider and pass basePath to it (I've set it to /<base-path>/api/auth/)
    (the docs say that SessionProvider is not needed for App Route, but it is still valid to help migrating from pages - in this case also because it makes basePath work)

References:

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

3 participants