nuxt-auth: Invalid path used for auth-endpoint

Environment

                                                          nuxi 9:54:13

Nuxt project info: nuxi 9:54:13



๐Ÿ‘‰ 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``

Image

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``

Image

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

Most upvoted comments

@agracia-foticos @brucetony @nam0107 @patriciorivera Please test the version from the fix PR if it solves the problem for you

npm i https://pkg.pr.new/@sidebase/nuxt-auth@992

I left the explanation in the PR body and for me this fix seems to work.

We will release 0.10.1-alpha.2 if 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 โค

@nam0107 Thank you for your report, I seem to have fixed it by resolving callbackUrl provided to useAuth functions. So if you do signIn({ 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

upd: Actually doing signin in production mode seems to reproduce, looking into it.

@phoenix-ru you are correct, Iโ€™m using Nuxt baseURL, how can I fix that, should I remove that config?

As said, if you could provide a quick reproduction using playground-authjs, I can attempt to fix it so that you donโ€™t need to disableInternalRouting. So far, setting

app: { baseURL: โ€˜/aax4โ€™, }, and providing

AUTH_ORIGIN=http://localhost:3000/aax4/api/auth

seems to work for me. It correctly redirects me to http://localhost:3000/aax4/api/auth/signin?callbackUrl=%2Fprotected%2Fglobally in both development and production.

@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

Image

Image

Image

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=/

@agracia-foticos @brucetony @nam0107 @patriciorivera Please test the version from the fix PR if it solves the problem for you

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.1 as I mentioned in #984

@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 callbackUrl to signIn, hereโ€™s how we do it (some details omitted):

const parsedQuery = z.object({ callbackUrl: z.string().nullish() }).safeParse(useRoute().query)

function triggerSignIn() {
  let callbackUrl = '/'
  if (parsedQuery.success && parsedQuery.data.callbackUrl) {
    callbackUrl = parsedQuery.data.callbackUrl
  }
  return signIn('azure-ad', { callbackUrl })
}

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 callbackUrl computations which should benefit both authjs provider usage and local as well. Please test it and leave your feedback ๐Ÿ™‚

npm i https://pkg.pr.new/@sidebase/nuxt-auth@fff679c

upd: Actually doing signin in production mode seems to reproduce, looking into it.


@phoenix-ru you are correct, Iโ€™m using Nuxt baseURL, how can I fix that, should I remove that config?

As said, if you could provide a quick reproduction using playground-authjs, I can attempt to fix it so that you donโ€™t need to disableInternalRouting. So far, setting

  app: { baseURL: '/aax4', },

and providing

AUTH_ORIGIN=http://localhost:3000/aax4/api/auth

seems to work for me. It correctly redirects me to http://localhost:3000/aax4/api/auth/signin?callbackUrl=%2Fprotected%2Fglobally in both development and production.

@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

@nam0107 I need way more information from you to reproduce it. Could you please fork this repo and use playground-authjs for 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 Nuxt baseURL which 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 $fetch implementation). I am patching them and writing unit tests atm, we have to postpone merging the PR (and releasing a broken alpha.2)

@agracia-foticos @brucetony @nam0107 @patriciorivera Please test the version from the fix PR if it solves the problem for you

npm i https://pkg.pr.new/@sidebase/nuxt-auth@992

I left the explanation in the PR body and for me this fix seems to work.

We will release 0.10.1-alpha.2 if I get positive results from you ๐Ÿ™‚

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!

Hi @agracia-foticos , thank you for reporting such issues, I will take a look today as we want to get pathing stable and robust in 0.10.

Could you please specify which version of nuxt-auth are you using?

โ€œ@sidebase/nuxt-authโ€: โ€œ0.10.1-alpha.1โ€,