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: ''
}
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.
No description
No description
No description
Solution:
Fixed it: Issue was because it was behind a proxy it recieved http instead of https
Jump to solution
1 Reply
Solution
Hexi
Hexi4d ago
Fixed it: Issue was because it was behind a proxy it recieved http instead of https

Did you find this page helpful?