nuxt-auth
nuxt-auth copied to clipboard
Invalid Url upgrading to 0.6.2
Environment
- Operating System:
Linux
- Node Version:
v18.15.0
- Nuxt Version:
3.8.2
- CLI Version:
3.10.0
- Nitro Version:
2.8.0
- Package Manager:
[email protected]
- Builder:
-
- User Config:
-
- Runtime Modules:
-
- Build Modules:
-
Reproduction
No response
Describe the bug
I'm upgrading from 0.5.0 to 0.6.2
this is my nuxt.config.ts
auth: { // @ts-ignore (isEnabled boolean type) //BE CAREFULL, With visual studio debugger isEnabled can't be false, fails... issue opened isEnabled : process.env.NUXT_AUTH_ENABLED=="true", //all environment variables are strings baseURL :
http://localhost:3000/api/auth, // The origin is set to the development origin. Change this when deploying to production by setting
originin this config before build-time or by exporting
AUTH_ORIGINby running
export AUTH_ORIGIN=... // Whether to add a global authentication middleware that will protect all pages without exclusion globalAppMiddleware : false, provider : { type: 'authjs' } },
My NuxtAuthHandler are in :
The error is:
{ "url": "/api/auth/callback/credentials", "statusCode": 500, "statusMessage": "", "message": "Invalid URL", "stack": "<pre><span class=\"stack internal\">at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)</span>\n<span class=\"stack internal\">at new NodeError (node:internal/errors:399:5)</span>\n<span class=\"stack internal\">at URL.onParseError (node:internal/url:566:9)</span>\n<span class=\"stack internal\">at new URL (node:internal/url:646:5)</span>\n<span class=\"stack internal\">at Object.redirect (./node_modules/next-auth/core/lib/default-callbacks.js:16:65)</span>\n<span class=\"stack internal\">at createCallbackUrl (./node_modules/next-auth/core/lib/callback-url.js:20:35)</span>\n<span class=\"stack internal\">at init (./node_modules/next-auth/core/init.js:131:48)</span>\n<span class=\"stack internal\">at AuthHandler (./node_modules/next-auth/core/index.js:131:28)</span>\n<span class=\"stack internal\">at process.processTicksAndRejections (node:internal/process/task_queues:95:5)</span>\n<span class=\"stack internal\">at <anonymous> (./node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.mjs:88:24)</span>\n<span class=\"stack internal\">at async Object.handler (./node_modules/h3/dist/index.mjs:1675:19)</span>\n<span class=\"stack internal\">at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1885:7)</span></pre>" }
Any idea that whats happend?
Additional context
No response
Logs
No response
Any solution??
Any notice?
i try a lot of diferent code, but in all versions of my code raises "invalid url", please i need help!!!
I faced a similar issue after upgrading nuxt-auth from 0.6.2 to 0.6.3 and next-auth from 4.21.1 to 4.22.5. I'm using a custom provider in my case, I had to set NEXTAUTH_URL
environment variable, same value than AUTH_ORIGIN
one.
I add NEXTAUTH_URL="http://localhost:3000/api/auth" to my .env but i have the same error: "invalid url"
Try NEXTAUTH_URL=http://localhost:3000
and AUTH_ORIGIN=http://localhost:3000
And my NuxtAuthHandler is located to <project-root>/server/api/auth/[...].ts
Try
NEXTAUTH_URL=http://localhost:3000
andAUTH_ORIGIN=http://localhost:3000
And my NuxtAuthHandler is located to<project-root>/server/api/auth/[...].ts
.env
/server/api/auth/[...].ts
nuxt.config.ts
Same error :(
Remove the space after equals sign for the NUXT_BASE_URL
environment variable in your .env file
Remove the space after equals sign for the
NUXT_BASE_URL
environment variable in your .env file
There isnt spaces in NUXT_BASE_URL :(
Try baseURL: process.env.NUXT_BASE_URL
in the nuxt.config.ts
Try
baseURL: process.env.NUXT_BASE_URL
in the nuxt.config.ts
It's the same!
Not works! :(
Maybe the environment variables are not available in your setup. Try to use hardcoded values for both isEnabled and baseURL settings. Or remove baseURL config from nuxt.config.ts file, the default is http://localhost:3000/api/auth like you want in development.
Hi @agracia-foticos,
As @davidlemaitre suspects, I think that somewhere a url is not being set correctly. Therefore I would recommend the following to try and debug this problem:
- remove all environment variables relating to auth
- Remove
baseURL
from thenuxt.config
(in development, NuxtAuth can automatically determine your origin) - If this does not work, please hard code
baseURL
in yournuxt.config
tolocalhost:3000
.
I also wanted to remind you that setting baseURL
in the nuxt config is for injecting the environment variable at build time and setting it via AUTH_ORIGIN
is for injecting it runtime. You do not need to set both, one is enough!
Hi @agracia-foticos,
As @davidlemaitre suspects, I think that somewhere a url is not being set correctly. Therefore I would recommend the following to try and debug this problem:
- remove all environment variables relating to auth
- Remove
baseURL
from thenuxt.config
(in development, NuxtAuth can automatically determine your origin)- If this does not work, please hard code
baseURL
in yournuxt.config
tolocalhost:3000
.I also wanted to remind you that setting
baseURL
in the nuxt config is for injecting the environment variable at build time and setting it viaAUTH_ORIGIN
is for injecting it runtime. You do not need to set both, one is enough!
nuxt.config.ts
the only key in .env its NUXT_AUTH_SECRET
same issue
[nuxt] [request error] [unhandled] [500] Invalid URL at __node_internal_captureLargerStackTrace (node:internal/errors:496:5) at new NodeError (node:internal/errors:405:5) at new URL (node:internal/url:778:13) at Object.redirect (./node_modules/next-auth/core/lib/default-callbacks.js:16:65) at createCallbackUrl (./node_modules/next-auth/core/lib/callback-url.js:20:35) at init (./node_modules/next-auth/core/init.js:131:48) at AuthHandler (./node_modules/next-auth/core/index.js:131:28) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at <anonymous> (./node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.mjs:88:24) at async Object.handler (./node_modules/h3/dist/index.mjs:1675:19) at async Server.toNodeHandle (./node_modules/h3/dist/index.mjs:1885:7)
@agracia-foticos Could you please show me your NuxtAuthHandler
(the file inside /api/auth/[...].ts
).
I feel like there may be an issue in there 😄
Otherwise, could you create a small reproduction of the issue? I think this would greatly help me, find the issue and expatiate the process!
@agracia-foticos Could you please show me your
NuxtAuthHandler
(the file inside/api/auth/[...].ts
). I feel like there may be an issue in there 😄Otherwise, could you create a small reproduction of the issue? I think this would greatly help me, find the issue and expatiate the process!
The NuxtAuthHandler
runs in 0.5.2 version... i think there isnt the problem here.
i try to give you a small reproduction, but it's going to be complicated
The NuxtAuthHandler runs in 0.5.2 version... i think there isnt the problem here.
I saw that the error originated from the section in nuxt-auth concering itself with the NuxtAuthHandler, which is why I wanted to verify, that the problem would not occur from there!
The NuxtAuthHandler runs in 0.5.2 version... i think there isnt the problem here.
I saw that the error originated from the section in nuxt-auth concering itself with the NuxtAuthHandler, which is why I wanted to verify, that the problem would not occur from there!
NuxtAuthHandler without our auth authentication... i delete the code into 'async authorize"
import CredentialsProvider from 'next-auth/providers/credentials'
import { NuxtAuthHandler } from '#auth'
import { GOOGLE_LOGIN, USER_PASSWORD_LOGIN } from '@/constants/wanapix'
import type { WebUser } from '@/types/fapi/WebUser'
export default NuxtAuthHandler({
pages: {
signIn: `/login`, //`/${LOGIN_SLUG}`
},
secret: <string>useRuntimeConfig().authSecret,
providers: [
CredentialsProvider.default({
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'Credentials',
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// e.g. domain, username, password, 2FA token, etc.
// You can pass any HTML attribute to the <input> tag through the object.
async authorize (credentials: WebUser) {
}
}),
],
callbacks: {
// Callback when the JWT is created / updated, see https://next-auth.js.org/configuration/callbacks#jwt-callback
jwt: async ({token, user}) => {
const isSignIn = user ? true : false;
if (isSignIn) {
(token as any) = user
}
return Promise.resolve(token);
},
// Callback whenever session is checked, see https://next-auth.js.org/configuration/callbacks#session-callback
session: async ({session, token}) => {
(session as any) = token;
return Promise.resolve(session);
},
},
})
Any idea?
I have upgraded the version to 0.6.3 but we have the same error :(
@agracia-foticos, does it work on local development, if you set no Environment variable at all? When starting the project in development mode, it should be able to auto get the URL. This would show if:
- The issue lies within your environment variables
- In something else
Other then that, there isn't much I can directly find inside the files and information you provided. If you could create a new empty project and try to replicate the issue, then I could look further into it. I myself am using NuxtAuth 0.6.3 in my own projects and have not encountered this issue.
Looks like I had a similar error
When I tried signIn('google')
it redirected me to the login page with invalid url
error in the console, although before it was opening google auth page right away
removing line
globalAppMiddleware: false
helped me
I remove
globalAppMiddleware:false
and works fine!!!!
Amazing! Seems to be an issue in the redirecting. Ill look into this and see why its caused!
Same issue on 0.6.7
[nuxt] [request error] [unhandled] [500] Invalid URL
at new URL (node:internal/url:787:36)
at ./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/lib/providers.js:55:19
at Array.reduce (
at normalizeOAuthOptions (./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/lib/providers.js:51:51)
at ./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/lib/providers.js:25:37
at Array.map (
at parseProviders (./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/lib/providers.js:15:38)
at init (./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/init.js:56:30)
at AuthHandler (./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next-auth/core/index.js:138:28)
Closed due to an old version. If anyone is still experiencing this issue, please check if it still exists in 0.8.0 and that the module has been setup using the new docs: https://auth.sidebase.io
Closed due to an old version. If anyone is still experiencing this issue, please check if it still exists in 0.8.0 and that the module has been setup using the new docs: https://auth.sidebase.io
I'm afraid it's still an issue in @sidebase/nuxt-auth:0.9.3 + next-auth:4.21.1.
I got "[500] Invalid URL" while calling signIn function.
Removing globalAppMiddleware: false,
from nuxt.config.ts
solved the issue.
Setting it to true
also solves the issue (but it's not what I wanted).