Setting baseUrl doesn't work when BETTER_AUTH_URL does

In my project, I have to specify the app url twice because I have the app url set as PUBLIC_URL and then I need to set BETTER_AUTH_URL as well to make better-auth work. I have tried setting it with baseUrl in the auth config, but the api always just gives a 404, even though it's set to the same url as the env variable.
9 Replies
Ping
Ping2w ago
Hello, just a few questions: * Are you setting testing the endpoints via auth.api or via authClient? * Is the PUBLIC_URL using the same format (eg including the protocol, and the domain, not just domain by itself) as the BETTER_AUTH_URL?
Andersmmg
AndersmmgOP2w ago
It's the same format, e.g. "http://localhost:3000" And I'm setting them in the server file like this:
export const auth = betterAuth({
baseURL: process.env.PUBLIC_URL
})
export const auth = betterAuth({
baseURL: process.env.PUBLIC_URL
})
Ping
Ping2w ago
And are you using auth.api or authClient to test endpoints?
Andersmmg
AndersmmgOP2w ago
authClient Though I have the same issue just trying cURL requests to the api as well
Ping
Ping2w ago
What do you mean? I think I'm missing some important context. Could you elaborate on your issue further?
Andersmmg
AndersmmgOP2w ago
For example, I set the baseURL to http://192.168.40.115:3000/ (my local ip) and start the server, I try a cURL request to http://192.168.40.115:3000/api/auth/ok and I get a 404 error from the framework, so it's not even going through better-auth. If I set BETTER_AUTH_URL to the exact same value, and remove baseURL, it works, so I have the URL set in 2 places in .env. Shouldn't setting this env variable and the baseURL value do the same thing?
Ping
Ping2w ago
Yeah they should, this is very odd. @bekacru , could you please check this out?
Andersmmg
AndersmmgOP2w ago
I've been trying to track down the cause but the best guess I have is that it's running in docker maybe?
Andersmmg
AndersmmgOP2w ago
GitHub
GitHub - andersmmg/better-auth-repro
Contribute to andersmmg/better-auth-repro development by creating an account on GitHub.

Did you find this page helpful?