Invalid base URL (only when running in docker)

Hello. I have setup better-auth in nuxt with bun. Running bun dev works fine. Running bun run build followed by bun preview works equally fine. My config so far is using github as login provider. But. Building the project with nixpacks, and then running the docker container gives better-auth error:
[info] [nuxi] Starting preview command: `node ./server/index.mjs`
[log] [nuxi]
Listening on http://[::]:3000
[BetterAuthError: Invalid base URL: "http://localhost:3000/". Please provide a valid base URL.] {
cause: undefined
}
[BetterAuthError: Invalid base URL: "http://localhost:3000/". Please provide a valid base URL.] {
cause: undefined
}
[info] [nuxi] Starting preview command: `node ./server/index.mjs`
[log] [nuxi]
Listening on http://[::]:3000
[BetterAuthError: Invalid base URL: "http://localhost:3000/". Please provide a valid base URL.] {
cause: undefined
}
[BetterAuthError: Invalid base URL: "http://localhost:3000/". Please provide a valid base URL.] {
cause: undefined
}
I can understand whats different between bulding and previewing directly on my machin vs running the container? Has anyone had a similar issue? Any advice is appreciated, I'm pulling hair 😛
1 Reply
nside
nside•7d ago
Hi, not much of help but maybe we can figure this thing out as I have the same problem myself with an AstroJS :astro: app with Bun , Turso as database and Drizzle adapter. When trying to run the app inside a Docker container I get the same message. The BETTER_AUTH_URL variable is passed at the container build time and also when starting the container, the app works perfectly when running the dev server locally... I did try to build the Docker image with Bun and then with Node (pnpm) to see it that is an issue but I get the same error in both cases. Also I noticed that the better-auth package had a very specific change exactly in the file where this error is thrown with the latest release 1.3.27 so I updated to this version but that did not to fix the issue, same error.

Did you find this page helpful?