Error: Invalid URL during signOut
Environment
- Operating System: Windows_NT
- Node Version: v22.12.0
- Nuxt Version: 3.19.2
- CLI Version: 3.28.0
- Nitro Version: 2.12.6
- Package Manager: [email protected]
- Builder: -
- User Config: compatibilityDate, devtools, build, experimental, sourcemap, imports, modules, auth, fonts, i18n, vite, runtimeConfig
- Runtime Modules: @vueuse/[email protected], @pinia/[email protected], @nuxt/[email protected], @nuxtjs/[email protected], @nuxt/[email protected], @sidebase/[email protected], ()
- Build Modules: -
Reproduction
I implemented sidebase-auth in a very straightforward way. Please see the bug description for details. The bug appears just during signOut method.
Describe the bug
Hi everyone, I am implementing sidebase in my nuxt project and I am encountering this issue only when I call "signOut" method of useAuth composable.
The error is the following: Error: Invalid URL
⁃ at new URL (node:internal/url:818:25) ⁃ at Object.redirect (<project_root>/node_modules/next-auth/core/lib/default-callbacks.js:17:65)
12 ┃ redirect({
13 ┃ url,
14 ┃ baseUrl
15 ┃ }) {
16 ┃
❯ 17 ┃ if (url.startsWith("/")) return ${baseUrl}${url};else if (new URL(url).origin === baseUrl) return url;
18 ┃ return baseUrl;
19 ┃ },
I put some logs before line 17 and I saw that "url" is always populated except when I click signOut which became undefined. I do not know if it is correct to have url = undefined during signOut but what I see is that the error is thrown when it tries to do url.startsWith("/") and/or (new URL(url).
By the way, my web app seems to work properly even if this error is triggered. Seems that is blocking for other people (https://github.com/nextauthjs/next-auth/issues/7956)
What I suggest is to just put a url && before each if statement in line 17 so that it'll skip directly to line 18 in case url is not a string.
Additional context
No response
Logs
Hi @AnthonyDM-Dev, sorry for the late reply, I am not entirely sure how you stumbled onto this as next-auth only seems to call callbacks.redirect when there's a valid value for it:
https://github.com/nextauthjs/next-auth/blob/1a70ee8e3b9ed5be5446a221c133bc8d26157a3f/packages/next-auth/src/core/lib/callback-url.ts#L23-L35
What I suggest is to just put a url && before each if statement in line 17 so that it'll skip directly to line 18 in case url is not a string.
Does doing so solve the issue for you? My guess would be not that the value is undefined, but rather that it's a non-correct URL being supplied, but please provide a bit more details so we can take a look
Hello 👋
Please provide a reproduction for this issue 🙏
How can I create a reproduction?
Please use one of the following links to reproduce your issue.
- https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
- https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox
Please ensure that the reproduction is as minimal as possible. This will allow us to isolate the issue as best as possible.
Here are some more amazing posts about the importance of reproductions:
This issue was closed because it was open for 14 days without a reproduction.