Magic link invalid url and baseURL issue

When I try to generate a magic link, I get this error:

Magic link error: TypeError: Invalid URL
    at new URL (node:internal/url:818:25)
    at file:///root/lumabooking/frontend/node_modules/better-auth/dist/plugins/magic-link/index.mjs:141:31
    at async internalHandler (file:///root/lumabooking/frontend/node_modules/better-call/dist/index.js:576:22)
    at async api.<computed> [as signInMagicLink] (file:///root/lumabooking/frontend/node_modules/better-auth/dist/api/index.mjs:534:22)
    at async eval (/root/lumabooking/frontend/src/lib/server/trpc/routers/v2/router.ts:234:23)
    at async resolveMiddleware (file:///root/lumabooking/frontend/node_modules/@trpc/server/dist/initTRPC-IT_6ZYJd.mjs:221:17)
    at async callRecursive (file:///root/lumabooking/frontend/node_modules/@trpc/server/dist/initTRPC-IT_6ZYJd.mjs:256:18)
    at async outputValidatorMiddleware (file:///root/lumabooking/frontend/node_modules/@trpc/server/dist/initTRPC-IT_6ZYJd.mjs:60:18)
    at async callRecursive (file:///root/lumabooking/frontend/node_modules/@trpc/server/dist/initTRPC-IT_6ZYJd.mjs:256:18)
    at async callRecursive (file:///root/lumabooking/frontend/node_modules/@trpc/server/dist/initTRPC-IT_6ZYJd.mjs:256:18) {
  code: 'ERR_INVALID_URL',
  input: ''
}


After digging into the stack trace, I noticed that ctx.context.baseURL inside the internal package is coming through as
undefined
. (screenshot attached)

I haven’t manually set a
baseURL
, but when I try to configure one explicitly, everything breaks—the API endpoint no longer works. Instead of the API handler responding, Svelte serves a 404 page (screenshots 2 and 3).

My guess is that the issue lies in Svelte’s routing/handler setup. Setting the
baseURL
seems to cause Svelte’s route handling to intercept the request, leading to the 404 page instead of correctly hitting the API.
79779DF8-C9D0-4B75-834C-9679295C43FF.png
A71694C1-4193-4781-8FB2-26BC5E5C54F3.png
51FD4AC7-4B31-4E94-AD85-B65FCCB3739F.png
Solution
Fixed it: Issue was because it was behind a proxy it recieved http instead of https
Was this page helpful?