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
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
?It's the same format, e.g. "http://localhost:3000"
And I'm setting them in the server file like this:
And are you using auth.api or authClient to test endpoints?
authClient
Though I have the same issue just trying cURL requests to the api as well
What do you mean? I think I'm missing some important context.
Could you elaborate on your issue further?
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?Yeah they should, this is very odd.
@bekacru , could you please check this out?
I've been trying to track down the cause but the best guess I have is that it's running in docker maybe?
Hopefully this helps!
https://github.com/andersmmg/better-auth-repro
GitHub
GitHub - andersmmg/better-auth-repro
Contribute to andersmmg/better-auth-repro development by creating an account on GitHub.