Regression in 1.3.17 (Nuxt 4.1.2): “Failed to parse URL from /api/auth/get-session” during SSR/middleware; works on 1.3.16 #2018

Closed
opened 2026-03-13 09:21:17 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @rasyidly on GitHub (Sep 25, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Upgrade better-auth from 1.3.16 to 1.3.17
  2. Use Nuxt global middleware that calls getSession() during SSR (via a composable or directly)
  3. Start dev server and navigate to any route that triggers the middleware
  4. Error appears: “Failed to parse URL from /api/auth/get-session”
  5. Downgrade to 1.3.16 → error disappears

Current vs. Expected behavior

Calling getSession() from SSR/global route middleware should work with a relative path, as in 1.3.16.
No need to provide an absolute baseURL in Nuxt SSR when client and server are on the same origin.

What version of Better Auth are you using?

1.3.17

System info

Nuxt: 4.1.2
Better Auth: 1.3.17 (broken), 1.3.16 (works)
@better-fetch/fetch: 1.1.18
Vue: 3.5.21
TypeScript: 5.9.2
OS: macOS
Node: (fill in your Node version)

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

  • The error originates from undici in Node when fetch is provided a relative URL. In 1.3.16, relative URLs worked in this context. In 1.3.17, the client seems to call a relative path in a Node environment where an absolute URL is now required (likely due to changes in how @better-fetch/fetch is used).
  • This is a regression between 1.3.16 and 1.3.17.

Stack Trace

Failed to parse URL from /api/auth/get-session

at node:internal/deps/undici/undici:13502:13
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async betterFetch (/nuxt/app/node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js:546:18)
at async $fetch (/nuxt/app/node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js:460:12)
at async Object.apply (/nuxt/app/node_modules/.pnpm/better-auth@1.3.17_vue@3.5.21_typescript@5.9.2_/node_modules/better-auth/dist/shared/better-auth.BAPVOPl3.mjs:193:16)
at async setup (/nuxt/app/app/composables/useAuth.ts:47:22)
at async /nuxt/app/app/middleware/auth.global.ts:13:94)
at async Object.callAsync (/nuxt/app/node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs:72:16)
at async /nuxt/app/node_modules/.pnpm/nuxt@4.1.2_@netlify+blobs@9.1.2_@parcel+watcher@2.5.1_@types+node@24.0.13_@vue+compiler_f489013827acd1da46bbfb7352a5dee3/node_modules/nuxt/dist/pages/runtime/plugins/router.js:186:28)
Originally created by @rasyidly on GitHub (Sep 25, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Upgrade better-auth from 1.3.16 to 1.3.17 2. Use Nuxt global middleware that calls getSession() during SSR (via a composable or directly) 3. Start dev server and navigate to any route that triggers the middleware 4. Error appears: “Failed to parse URL from /api/auth/get-session” 5. Downgrade to 1.3.16 → error disappears ### Current vs. Expected behavior Calling getSession() from SSR/global route middleware should work with a relative path, as in 1.3.16. No need to provide an absolute baseURL in Nuxt SSR when client and server are on the same origin. ### What version of Better Auth are you using? 1.3.17 ### System info ```bash Nuxt: 4.1.2 Better Auth: 1.3.17 (broken), 1.3.16 (works) @better-fetch/fetch: 1.1.18 Vue: 3.5.21 TypeScript: 5.9.2 OS: macOS Node: (fill in your Node version) ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context - The error originates from undici in Node when fetch is provided a relative URL. In 1.3.16, relative URLs worked in this context. In 1.3.17, the client seems to call a relative path in a Node environment where an absolute URL is now required (likely due to changes in how @better-fetch/fetch is used). - This is a regression between 1.3.16 and 1.3.17. ## Stack Trace ``` Failed to parse URL from /api/auth/get-session at node:internal/deps/undici/undici:13502:13 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async betterFetch (/nuxt/app/node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js:546:18) at async $fetch (/nuxt/app/node_modules/.pnpm/@better-fetch+fetch@1.1.18/node_modules/@better-fetch/fetch/dist/index.js:460:12) at async Object.apply (/nuxt/app/node_modules/.pnpm/better-auth@1.3.17_vue@3.5.21_typescript@5.9.2_/node_modules/better-auth/dist/shared/better-auth.BAPVOPl3.mjs:193:16) at async setup (/nuxt/app/app/composables/useAuth.ts:47:22) at async /nuxt/app/app/middleware/auth.global.ts:13:94) at async Object.callAsync (/nuxt/app/node_modules/.pnpm/unctx@2.4.1/node_modules/unctx/dist/index.mjs:72:16) at async /nuxt/app/node_modules/.pnpm/nuxt@4.1.2_@netlify+blobs@9.1.2_@parcel+watcher@2.5.1_@types+node@24.0.13_@vue+compiler_f489013827acd1da46bbfb7352a5dee3/node_modules/nuxt/dist/pages/runtime/plugins/router.js:186:28) ```
GiteaMirror added the nuxt label 2026-03-13 09:21:17 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 25, 2025):

Hi @rasyidly! I'm Dosu and I’m helping the better-auth team.

This is a confirmed regression in Better Auth 1.3.17 affecting Nuxt SSR/global middleware when calling getSession() with a relative URL. The root cause is a change in how the client config and base URL are resolved: a new loadEnv parameter was added to control whether environment variables are used for baseURL resolution. In Nuxt SSR, this now defaults to using relative URLs, but if the fetch implementation (like undici in Node) requires absolute URLs, it will throw a "Failed to parse URL" error if given a relative path. This change was introduced in PRs #4887 and #4888.

There’s an existing issue tracking this: GitHub issue #4722. The recommended workaround is to wrap your fetch so it converts absolute URLs to relative paths before calling useFetch, which ensures cookies are forwarded and avoids the undici error. Example:

const relativeFetch = ((url: string, opts?: any) => {
  try {
    if (url.startsWith('http')) url = new URL(url).pathname
  } catch {}
  return useFetch(url, opts)
}) as any

const { data: session } = await authClient.useSession(relativeFetch)

Alternatively, downgrading to Better Auth 1.3.16 (or 1.3.9) restores the previous behavior, as those versions use relative paths by default. This is suited for GitHub and is being tracked for a fix. For more details and discussion, see the related issue.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 25, 2025): <!-- Greeting --> Hi @rasyidly! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a confirmed regression in Better Auth 1.3.17 affecting Nuxt SSR/global middleware when calling getSession() with a relative URL. The root cause is a change in how the client config and base URL are resolved: a new `loadEnv` parameter was added to control whether environment variables are used for baseURL resolution. In Nuxt SSR, this now defaults to using relative URLs, but if the fetch implementation (like undici in Node) requires absolute URLs, it will throw a "Failed to parse URL" error if given a relative path. This change was introduced in PRs [#4887](https://github.com/better-auth/better-auth/pull/4887) and [#4888](https://github.com/better-auth/better-auth/pull/4888). There’s an existing issue tracking this: [GitHub issue #4722](https://github.com/better-auth/better-auth/issues/4722). The recommended workaround is to wrap your fetch so it converts absolute URLs to relative paths before calling useFetch, which ensures cookies are forwarded and avoids the undici error. Example: ```typescript const relativeFetch = ((url: string, opts?: any) => { try { if (url.startsWith('http')) url = new URL(url).pathname } catch {} return useFetch(url, opts) }) as any const { data: session } = await authClient.useSession(relativeFetch) ``` Alternatively, downgrading to Better Auth 1.3.16 (or 1.3.9) restores the previous behavior, as those versions use relative paths by default. This is suited for GitHub and is being tracked for a fix. For more details and discussion, see [the related issue](https://github.com/better-auth/better-auth/issues/4722). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/971f9327-c9c7-40e7-ac4d-31ad47d0752e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/971f9327-c9c7-40e7-ac4d-31ad47d0752e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/971f9327-c9c7-40e7-ac4d-31ad47d0752e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/971f9327-c9c7-40e7-ac4d-31ad47d0752e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/971f9327-c9c7-40e7-ac4d-31ad47d0752e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/971f9327-c9c7-40e7-ac4d-31ad47d0752e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/971f9327-c9c7-40e7-ac4d-31ad47d0752e?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4902)
Author
Owner

@rasyidly commented on GitHub (Sep 25, 2025):

Update:

If I add baseURL explicitly in createAuthClient (line 22 in my composable):

const client = createAuthClient({
  baseURL: "http://localhost:3000/api/auth", // added here, and works, but it's not necessary when single domain i think
  plugins: [...]
})

the error disappears and everything works.
But this shouldn’t be necessary—my app is fullstack Nuxt, same domain, no proxy, and in previous version it worked fine without baseURL. Setting or removing .env BETTER_AUTH_URL has no effect in my machine.

Suggestion:
Can you restore the previous behavior where relative URLs work by default in SSR/Node? Requiring baseURL for same-origin apps is not ergonomic and breaks backward compatibility. 😬

Thanks!

@rasyidly commented on GitHub (Sep 25, 2025): **Update:** If I add `baseURL` explicitly in createAuthClient (line 22 in my composable): ```ts const client = createAuthClient({ baseURL: "http://localhost:3000/api/auth", // added here, and works, but it's not necessary when single domain i think plugins: [...] }) ``` the error disappears and everything works. But this shouldn’t be necessary—my app is fullstack Nuxt, same domain, no proxy, and in previous version it worked fine without baseURL. Setting or removing .env BETTER_AUTH_URL has no effect in my machine. **Suggestion:** Can you restore the previous behavior where relative URLs work by default in SSR/Node? Requiring baseURL for same-origin apps is not ergonomic and breaks backward compatibility. 😬 Thanks!
Author
Owner

@Mateleo commented on GitHub (Sep 25, 2025):

@rasyidly I'm proposing a PR an other Nuxt issue. My Nuxt app is also not working since 1.3.10 (working on 1.3.9).
See this https://github.com/better-auth/better-auth/issues/4722

@Mateleo commented on GitHub (Sep 25, 2025): @rasyidly I'm proposing a PR an other Nuxt issue. My Nuxt app is also not working since 1.3.10 (working on 1.3.9). See this https://github.com/better-auth/better-auth/issues/4722
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2018