nuxt-auth: 'Invalid URL' on v 0.10.0
Environment
- Operating System:
Linux - Node Version:
v22.8.0 - Nuxt Version:
3.14.1592 - CLI Version:
3.17.1 - Nitro Version:
2.10.4 - Package Manager:
yarn@4.3.1 - Builder:
- - User Config:
- - Runtime Modules:
- - Build Modules:
-
Reproduction
i have this config:
auth: {
// @ts-ignore (isEnabled boolean type)
//BE CAREFULL, With visual studio debugger isEnabled can't be false, fails... issue opened
isEnabled : true, //all environment variables are strings
baseURL : `${process.env.NUXT_BASE_URL}/api/auth`, // The origin is set to the development origin. Change this when deploying to production by setting `origin` in this config before build-time or by exporting `AUTH_ORIGIN` by running `export AUTH_ORIGIN=...`
// Whether to add a global authentication middleware that will protect all pages without exclusion
globalAppMiddleware : true,
provider : { type: 'authjs' },
sessionRefresh : {
enablePeriodically : 86400000, //refresh the session every day
enableOnWindowFocus : true
}
},
- go to localhost:3000
- Server responses with error 500 and
error {
url: '/',
statusCode: 500,
statusMessage: '',
message: 'Invalid URL',
stack: '<pre><span class="stack internal">at new URL (node:internal/url:816:29)</span>\n' +
'<span class="stack internal">at /home/web/var/www/site/node_modules/@sidebase/nuxt-auth/dist/runtime/composables/authjs/utils/navigateToAuthPage.js:15:31</span>\n' +
'<span class="stack internal">at runNextTicks (node:internal/process/task_queues:65:5)</span>\n' +
'<span class="stack internal">at process.processImmediate (node:internal/timers:459:9)</span>\n' +
'<span class="stack internal">at process.callbackTrampoline (node:internal/async_hooks:130:17)</span>\n' +
'<span class="stack internal">at async Object.callAsync (/home/web/var/www/site/node_modules/unctx/dist/index.mjs:72:16)</span>\n' +
'<span class="stack internal">at async Object.callAsync (/home/web/var/www/site/node_modules/unctx/dist/index.mjs:72:16)</span>\n' +
'<span class="stack internal">at async /home/web/var/www/site/node_modules/nuxt/dist/pages/runtime/plugins/router.js:180:26</span></pre>'
}
3. Automatic, (without any action), redirects to http://localhost:3000/login?callbackUrl=http://localhost:3000/
If i turn globalAppMiddleware to false, works OK
Describe the bug
i have this config:
auth: {
// @ts-ignore (isEnabled boolean type)
//BE CAREFULL, With visual studio debugger isEnabled can't be false, fails... issue opened
isEnabled : true, //all environment variables are strings
baseURL : `${process.env.NUXT_BASE_URL}/api/auth`, // The origin is set to the development origin. Change this when deploying to production by setting `origin` in this config before build-time or by exporting `AUTH_ORIGIN` by running `export AUTH_ORIGIN=...`
// Whether to add a global authentication middleware that will protect all pages without exclusion
globalAppMiddleware : true,
provider : { type: 'authjs' },
sessionRefresh : {
enablePeriodically : 86400000, //refresh the session every day
enableOnWindowFocus : true
}
},
- go to localhost:3000
- Server responses with error 500 and
error {
url: '/',
statusCode: 500,
statusMessage: '',
message: 'Invalid URL',
stack: '<pre><span class="stack internal">at new URL (node:internal/url:816:29)</span>\n' +
'<span class="stack internal">at /home/web/var/www/site/node_modules/@sidebase/nuxt-auth/dist/runtime/composables/authjs/utils/navigateToAuthPage.js:15:31</span>\n' +
'<span class="stack internal">at runNextTicks (node:internal/process/task_queues:65:5)</span>\n' +
'<span class="stack internal">at process.processImmediate (node:internal/timers:459:9)</span>\n' +
'<span class="stack internal">at process.callbackTrampoline (node:internal/async_hooks:130:17)</span>\n' +
'<span class="stack internal">at async Object.callAsync (/home/web/var/www/site/node_modules/unctx/dist/index.mjs:72:16)</span>\n' +
'<span class="stack internal">at async Object.callAsync (/home/web/var/www/site/node_modules/unctx/dist/index.mjs:72:16)</span>\n' +
'<span class="stack internal">at async /home/web/var/www/site/node_modules/nuxt/dist/pages/runtime/plugins/router.js:180:26</span></pre>'
}
3. Automatic, (without any action), redirects to http://localhost:3000/login?callbackUrl=http://localhost:3000/
If i turn globalAppMiddleware to false, works OK
Additional context
No response
Logs
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 18
Commits related to this issue
- fix(#970): make redirect implementation match Nuxt's — committed to sidebase/nuxt-auth by phoenix-ru 2 years ago
- fix(#970): make redirect implementation match Nuxt's (#985) Co-authored-by: Zoey <zoeykaiser8@gmail.com> — committed to sidebase/nuxt-auth by phoenix-ru 2 years ago
Any advance?
@phoenix-ru Setting
disableInternalRouting: truewhile havingglobalAppMiddlewareenabled on 0.10.0 works on my machine™ and also seems to solve #922 on my side.I’m able to replicate that as well on
0.10.0and it seems to originate in the following code introduced in 578800588784f32275f3980a685987fef5ef71da: https://github.com/sidebase/nuxt-auth/blob/52d4b9a5b48431eb9d522865410d209c6d66a613/src/runtime/composables/authjs/utils/navigateToAuthPage.ts#L20-L28In my case the
hrefpassed tonavigateToAuthPageis/api/auth/signin?callback=.... I do havebaseURLset tohttp://localhost:3000/api/auth[0], howeverruntimeConfig.public.auth.baseURL[1] is still/api/auth, resulting in theresolveApiUrlPath("signin", runtimeConfig)generating that invalid URL.I disabled the
defaultProviderduring debugging, as the automatic redirect for the login didn’t seem to set the state cookie correctly (#922), hence the redirect via useAuth.signIn().https://github.com/sidebase/nuxt-auth/blob/52d4b9a5b48431eb9d522865410d209c6d66a613/src/runtime/utils/url.ts#L15-L26
[0] my config in
nuxt.config.ts[1]
runtimeConfiginresolveApiUrlPath@agracia-foticos You can try using the
nexttag which includes this fix: https://www.npmjs.com/package/@sidebase/nuxt-auth/v/0.10.1-alpha.1?activeTab=versionsWORKS updating https://auth.sidebase.io/upgrade/version-0.10.0#urls-are-now-joined And without
disableInternalRouting : true@agracia-foticos Can you please try the fix done in #985?
i upgrade from “@sidebase/nuxt-auth”: “0.9.4”,