Error: proxy request failed, cannot connect to the specified address
I'm getting this error on my production build on Cloudflare Workers.
Here is the source code https://github.com/safecircleia/waitlist all enviroment variables are setup correctly and it works locally
Solution:Jump to solution
Ok, I just needed to add enviroments variable in the runtime options not just in the build configuration
20 Replies
Nor email or github/google or any oauth works
Trying to visit manually
/api/auth/email
gets me this error
I'm getting errors saying that they couldn't found the enviroment variables but they are setup correctly and can be accesed during build times

in auth.ts, you have to add the environment variables yourself since they have to be imported in cloudflare from the cloudflare package.
Do you have an example?
Options | Better Auth
Better Auth configuration options reference.
I have it like this https://github.com/safecircleia/waitlist/blob/main/lib%2Fauth.ts
So you suggest setting the variables on the file instead of a .env file?
GitHub
waitlist/lib/auth.ts at main · safecircleia/waitlist
The official SafeCircle waitlist webpage. Contribute to safecircleia/waitlist development by creating an account on GitHub.
no
you do not have the secret specified in there.
you should make it access the .env
you have to use the cloudflare specific way to access the env
Ill try that, I saw it in the doc how it worked.
Thanks!
Cloudflare Docs
Compatibility flags
Opt into a specific features of the Workers runtime for your Workers project.
or you have to change the compat date
your compat date is before the change of process.env
so process.env is empty
I have this at my compat date
Mar 25, 2025
yes, too old.
as you can see in the link
it was only added on first of april that you can use process.env.
Do I have to only change the compatibility date and add this flag
nodejs_compat_populate_process_env
? I've added those but still doesn't work, I'm getting this error when trying to signin with social oauth
progress, good
yes, error is different but I'm still with the same behavior as before. I can't signin using oauth (social) and I can signin with email but I can't get pass the 2fa screen with a 500 error.
Do I hve to setup something in the cloudflare worker side?
It works locally without any problems using
pnpm wrangler dev
I´m still getting the same error on the build at cloudflre workers
Well, progress, now I'm getting this error
I've setup both BETTER_AUTH_SECRET
and NEXT_PUBLIC_APP_URL
to https://app.safecircle.tech
Fixed it but now I'm back to the [2m2025-05-18T00:41:06.533Z[0m [31mERROR[0m [1m[Better Auth]:[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.
Solution
Ok, I just needed to add enviroments variable in the runtime options not just in the build configuration
hi, were you able to fix this issue?
Yes
i figured that my environment variables are not loading correctly