nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

Error: Invalid URL during signOut

Open AnthonyDM-Dev opened this issue 5 months ago • 2 comments

Environment

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


AnthonyDM-Dev avatar Sep 30 '25 15:09 AnthonyDM-Dev

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

phoenix-ru avatar Oct 31 '25 14:10 phoenix-ru

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:

github-actions[bot] avatar Oct 31 '25 14:10 github-actions[bot]

This issue was closed because it was open for 14 days without a reproduction.

github-actions[bot] avatar Nov 15 '25 02:11 github-actions[bot]