nuxt-auth: Invalid path used for auth-endpoint
Environment
nuxi 9:54:13
Nuxt project info: nuxi 9:54:13
- Operating System: Linux
- Node Version: v18.19.1
- Nuxt Version: 3.14.1592
- CLI Version: 3.20.0
- Nitro Version: 2.10.4
- Package Manager: yarn@4.6.0
- Builder: -
- User Config: srcDir, devtools, ssr, modules, pwa, css, tailwindcss, extends, runtimeConfig, compatibilityDate
- Runtime Modules: @business/auth-internal@1.0.0, @business/factory-api@1.0.0, @business/erp-api@1.0.0, nuxt-api-party@2.1.2, @pinia/nuxt@0.5.5, @vite-pwa/nuxt@0.10.6
- Build Modules: -
๐ Report an issue: https://github.com/nuxt/nuxt/issues/new?template=bug-report.yml ๐ Suggest an improvement: https://github.com/nuxt/nuxt/discussions/new ๐ Read documentation: https://nuxt.com
Reproduction
Invalid path used for auth-endpoint. Supply either one path parameter (e.g., /api/auth/session) or two (e.g., /api/auth/signin/githubafter the base path (in previous examples base path was:/api/auth/. Received signin,signin,wso2``
With type oauth
id: 'wso2', type: 'oauth',
Produces http://localhost:3000/api/auth/signin/signin/wso2
Describe the bug
Invalid path used for auth-endpoint. Supply either one path parameter (e.g., /api/auth/session) or two (e.g., /api/auth/signin/githubafter the base path (in previous examples base path was:/api/auth/. Received signin,signin,wso2``
With type oauth
id: 'wso2', type: 'oauth',
Produces http://localhost:3000/api/auth/signin/signin/wso2
Additional context
No response
Logs
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 34 (1 by maintainers)
Commits related to this issue
- fix(#990): use a dedicated `host` calculation for `authjs` — committed to sidebase/nuxt-auth by phoenix-ru 2 years ago
- fix(#990): revamp callbackUrl computation — committed to sidebase/nuxt-auth by phoenix-ru 2 years ago
- fix(#990): use a dedicated `host` calculation for `authjs` (#992) * fix(#990): use a dedicated `host` calculation for `authjs` * chore: remove unused imports * fix: pass `Host` header for correct i... — committed to sidebase/nuxt-auth by phoenix-ru 2 years ago
@agracia-foticos @brucetony @nam0107 @patriciorivera Please test the version from the fix PR if it solves the problem for you
I left the explanation in the PR body and for me this fix seems to work.
We will release
0.10.1-alpha.2if I get positive results from you ๐@phoenix-ru it works and fixed redirect issue, can you publish it?
The fix for this issue has now been published in https://github.com/sidebase/nuxt-auth/releases/tag/0.10.1. Thank you for reporting and helping us resolve it โค
@phoenix-ru I upgraded to this version https://pkg.pr.new/@sidebase/nuxt-auth@fff679c but it throw 500 [nuxt] instance unavailable when the first time I access https://rpperf-gui.dev-vie.int.compax.at/aax4 then it redirect me to https://rpperf-gui.dev-vie.int.compax.at/aax4/login?callbackUrl=https://rpperf-gui.dev-vie.int.compax.at with wrong callbackUrl=https://rpperf-gui.dev-vie.int.compax.at I expect it should be https://rpperf-gui.dev-vie.int.compax.at/aax4 Could we have a quick session, I will show you the issue directly?
video: https://www.loom.com/share/c87328f584d84c1eb09d9cfb107df371?sid=895ac817-55dc-4d74-a7e0-ecc488ecc790
@nam0107 Thank you for your report, I seem to have fixed it by resolving
callbackUrlprovided touseAuthfunctions. So if you dosignIn({ callbackUrl: '/my-custom-callback' }), it will automatically resolve to/aax4/my-custom-callback, which gets rid of 404 you are experiencing ๐I am testing it further and will push my changes to the same PR later today, so youโd be able to test it.
I am not sure though that it would resolve exactly your issue, so letโs iterate
@phoenix-ru In local with subpath, it also work for me when I deploy it to my domain, I point this url https://rpperf-gui.dev-vie.int.compax.at/aax4 the app, not only https://rpperf-gui.dev-vie.int.compax.at, it has the duplicate isssue ๐ฅฒ
@phoenix-ru It works fine in my local without subpath, but when I deploy to my server, I used a subpath like /aax4 it seem has an issue about the url path
when I go to https://rpperf-gui.dev-vie.int.compax.at/aax4 without loged in, it redirect me to https://rpperf-gui.dev-vie.int.compax.at/aax4/aax4/api/auth/signin?callbackUrl=/
It works for me. Thank you very much @phoenix-ru for such a quick response to the situation.
This looks very similar to the issues I encountered when testing
0.10.1-alpha.1as I mentioned in #984Sorry, copied the wrong commit. The correct one is indeed https://github.com/sidebase/nuxt-auth/pull/992/commits/e7cfc2df5daf3eaa0b6d70c6e14409b259162152
@nam0107 I was able to reproduce and fix the double path problem in https://github.com/sidebase/nuxt-auth/pull/992/commits/9a67eca77b2642a6f3205aa805e63170f24a1d56. If you use a custom login page, you just need to supply
callbackUrltosignIn, hereโs how we do it (some details omitted):You donโt need zod, I just left it in the snippet to show how it can be validated.
@phoenix-ru I still get callbackUrl=https://rpperf-gui.dev-vie.int.compax.at/, I also send you an email with other config, can you check your email.
@nam0107 The new version is out, I tested your usecase specifically and did quite some changes to
callbackUrlcomputations which should benefit bothauthjsprovider usage andlocalas well. Please test it and leave your feedback ๐upd: Actually doing signin in production mode seems to reproduce, looking into it.
As said, if you could provide a quick reproduction using
playground-authjs, I can attempt to fix it so that you donโt need todisableInternalRouting. So far, settingand providing
seems to work for me. It correctly redirects me to
http://localhost:3000/aax4/api/auth/signin?callbackUrl=%2Fprotected%2Fgloballyin both development and production.@nam0107 I need way more information from you to reproduce it. Could you please fork this repo and use
playground-authjsfor a reproduction? I think that you are using some Nuxt options related to paths, which make the app behave so. I suspect that you have set NuxtbaseURLwhich leads to Nuxt automatically adding it to every navigation.Note that you can always set
disableInternalRouting: true. This will have slight performance penalty, but it will force the module to always use absolute paths when navigating/making queries.FYI: Recent changes actually uncovered a lot more issues with the pathing for
authjs. Some pretty serious ones, such as #973 which hit some edge-cases of Nuxt itself (i.e. of their$fetchimplementation). I am patching them and writing unit tests atm, we have to postpone merging the PR (and releasing a broken alpha.2)Also worked for me, tested with both base config and with a custom base URL and the endpoints resolved as expected, thanks for the quick patch!
Possibly same issue: https://github.com/sidebase/nuxt-auth/issues/984#issuecomment-2601719674
โ@sidebase/nuxt-authโ: โ0.10.1-alpha.1โ,