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
{
"source": {
"level": "error",
"message": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address",
"$cloudflare": {
"$metadata": {
"id": "01JVA5N0GT3X8G538VFFW74Z08",
"type": "cf-worker",
"error": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address"
}
}
},
"dataset": "cloudflare-workers",
"timestamp": "2025-05-15T14:30:23.514Z",
"$workers": {
"truncated": false,
"event": {
"request": {
"url": "https://app.safecircle.tech/api/auth/sign-in/email",
"method": "POST",
"path": "/api/auth/sign-in/email"
}
},
"outcome": "ok",
"scriptName": "safecircle-waitlist",
"eventType": "fetch",
"executionModel": "stateless",
"scriptVersion": {
"id": "981400c9-b4be-4c32-9de0-78df40d72017"
},
"requestId": "9403553cadf9026b"
},
"$metadata": {
"id": "01JVA5N0GT3X8G538VFFW74Z08",
"requestId": "9403553cadf9026b",
"trigger": "POST /api/auth/sign-in/email",
"service": "safecircle-waitlist",
"level": "error",
"error": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address",
"message": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address",
"account": "537639845b3a2365ae57881fbcbd6eee",
"type": "cf-worker",
"fingerprint": "adf6643df0abd1a3726de506411bd13b",
"origin": "fetch"
},
"links": []
}
{
"source": {
"level": "error",
"message": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address",
"$cloudflare": {
"$metadata": {
"id": "01JVA5N0GT3X8G538VFFW74Z08",
"type": "cf-worker",
"error": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address"
}
}
},
"dataset": "cloudflare-workers",
"timestamp": "2025-05-15T14:30:23.514Z",
"$workers": {
"truncated": false,
"event": {
"request": {
"url": "https://app.safecircle.tech/api/auth/sign-in/email",
"method": "POST",
"path": "/api/auth/sign-in/email"
}
},
"outcome": "ok",
"scriptName": "safecircle-waitlist",
"eventType": "fetch",
"executionModel": "stateless",
"scriptVersion": {
"id": "981400c9-b4be-4c32-9de0-78df40d72017"
},
"requestId": "9403553cadf9026b"
},
"$metadata": {
"id": "01JVA5N0GT3X8G538VFFW74Z08",
"requestId": "9403553cadf9026b",
"trigger": "POST /api/auth/sign-in/email",
"service": "safecircle-waitlist",
"level": "error",
"error": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address",
"message": "# SERVER_ERROR: Error: proxy request failed, cannot connect to the specified address",
"account": "537639845b3a2365ae57881fbcbd6eee",
"type": "cf-worker",
"fingerprint": "adf6643df0abd1a3726de506411bd13b",
"origin": "fetch"
},
"links": []
}
Solution:
Ok, I just needed to add enviroments variable in the runtime options not just in the build configuration
Jump to solution
20 Replies
Tresillo
TresilloOP4mo ago
Nor email or github/google or any oauth works
Tresillo
TresilloOP4mo ago
Trying to visit manually /api/auth/email gets me this error
No description
Tresillo
TresilloOP4mo ago
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
No description
Tobias
Tobias4mo ago
in auth.ts, you have to add the environment variables yourself since they have to be imported in cloudflare from the cloudflare package.
Tresillo
TresilloOP4mo ago
Do you have an example?
Tresillo
TresilloOP4mo ago
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.
Tobias
Tobias4mo ago
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
Tresillo
TresilloOP4mo ago
Ill try that, I saw it in the doc how it worked. Thanks!
Tobias
Tobias4mo ago
Cloudflare Docs
Compatibility flags
Opt into a specific features of the Workers runtime for your Workers project.
Tobias
Tobias4mo ago
or you have to change the compat date your compat date is before the change of process.env so process.env is empty
Tresillo
TresilloOP4mo ago
I have this at my compat date Mar 25, 2025
Tobias
Tobias4mo ago
yes, too old. as you can see in the link it was only added on first of april that you can use process.env.
Tresillo
TresilloOP4mo ago
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
{
"source": {
"message": "Promise will never complete.",
"exception": {
"name": "Error",
"message": "Promise will never complete.",
"timestamp": 1747519340093
},
"$cloudflare": {
"$metadata": {
"id": "01JVG49ZHXDASR96ECFBW92XNH",
"type": "cf-worker",
"error": "Promise will never complete."
}
}
},
"dataset": "cloudflare-workers",
"timestamp": "2025-05-17T22:02:20.093Z",
"$workers": {
"truncated": false,
"event": {
"request": {
"url": "https://app.safecircle.tech/api/auth/sign-in/social",
"method": "POST",
"path": "/api/auth/sign-in/social"
}
},
"outcome": "exception",
"scriptName": "safecircle-waitlist",
"eventType": "fetch",
"executionModel": "stateless",
"scriptVersion": {
"id": "c5509028-42a6-4929-838c-1d58215000b5"
},
"requestId": "941666038bad5e1d"
},
"$metadata": {
"id": "01JVG49ZHXDASR96ECFBW92XNH",
"requestId": "941666038bad5e1d",
"trigger": "POST /api/auth/sign-in/social",
"service": "safecircle-waitlist",
"level": "error",
"error": "Promise will never complete.",
"message": "Promise will never complete.",
"account": "537639845b3a2365ae57881fbcbd6eee",
"type": "cf-worker",
"fingerprint": "abea7996faee7b989a2170a6402844b0",
"origin": "fetch"
},
"links": []
}
{
"source": {
"message": "Promise will never complete.",
"exception": {
"name": "Error",
"message": "Promise will never complete.",
"timestamp": 1747519340093
},
"$cloudflare": {
"$metadata": {
"id": "01JVG49ZHXDASR96ECFBW92XNH",
"type": "cf-worker",
"error": "Promise will never complete."
}
}
},
"dataset": "cloudflare-workers",
"timestamp": "2025-05-17T22:02:20.093Z",
"$workers": {
"truncated": false,
"event": {
"request": {
"url": "https://app.safecircle.tech/api/auth/sign-in/social",
"method": "POST",
"path": "/api/auth/sign-in/social"
}
},
"outcome": "exception",
"scriptName": "safecircle-waitlist",
"eventType": "fetch",
"executionModel": "stateless",
"scriptVersion": {
"id": "c5509028-42a6-4929-838c-1d58215000b5"
},
"requestId": "941666038bad5e1d"
},
"$metadata": {
"id": "01JVG49ZHXDASR96ECFBW92XNH",
"requestId": "941666038bad5e1d",
"trigger": "POST /api/auth/sign-in/social",
"service": "safecircle-waitlist",
"level": "error",
"error": "Promise will never complete.",
"message": "Promise will never complete.",
"account": "537639845b3a2365ae57881fbcbd6eee",
"type": "cf-worker",
"fingerprint": "abea7996faee7b989a2170a6402844b0",
"origin": "fetch"
},
"links": []
}
Tobias
Tobias4mo ago
progress, good
Tresillo
TresilloOP4mo ago
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
{
"source": {
"level": "error",
"message": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"$cloudflare": {
"$metadata": {
"id": "01JVGA6NWAQ61VK3VN4Y5QBXQE",
"type": "cf-worker",
"error": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"errorPattern": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"messagePattern": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options."
}
}
},
"dataset": "cloudflare-workers",
"timestamp": "2025-05-17T23:45:23.338Z",
"$workers": {
"truncated": false,
"event": {
"request": {
"url": "https://app.safecircle.tech/api/auth/sign-in/social",
"method": "POST",
"path": "/api/auth/sign-in/social"
}
},
"outcome": "ok",
"scriptName": "safecircle-waitlist",
"eventType": "fetch",
"executionModel": "stateless",
"scriptVersion": {
"id": "6caedba6-53c0-4eda-bff8-3e1d569e2f8f"
},
"requestId": "9416fcf7bf58cfc7"
},
"$metadata": {
"id": "01JVGA6NWAQ61VK3VN4Y5QBXQE",
"requestId": "9416fcf7bf58cfc7",
"trigger": "POST /api/auth/sign-in/social",
"service": "safecircle-waitlist",
"level": "error",
"error": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"message": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"account": "537639845b3a2365ae57881fbcbd6eee",
"type": "cf-worker",
"fingerprint": "e36b09522b8d83150f98181b2afd807d",
"origin": "fetch",
"messageTemplate": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"errorTemplate": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options."
},
"links": []
}
{
"source": {
"level": "error",
"message": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"$cloudflare": {
"$metadata": {
"id": "01JVGA6NWAQ61VK3VN4Y5QBXQE",
"type": "cf-worker",
"error": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"errorPattern": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"messagePattern": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options."
}
}
},
"dataset": "cloudflare-workers",
"timestamp": "2025-05-17T23:45:23.338Z",
"$workers": {
"truncated": false,
"event": {
"request": {
"url": "https://app.safecircle.tech/api/auth/sign-in/social",
"method": "POST",
"path": "/api/auth/sign-in/social"
}
},
"outcome": "ok",
"scriptName": "safecircle-waitlist",
"eventType": "fetch",
"executionModel": "stateless",
"scriptVersion": {
"id": "6caedba6-53c0-4eda-bff8-3e1d569e2f8f"
},
"requestId": "9416fcf7bf58cfc7"
},
"$metadata": {
"id": "01JVGA6NWAQ61VK3VN4Y5QBXQE",
"requestId": "9416fcf7bf58cfc7",
"trigger": "POST /api/auth/sign-in/social",
"service": "safecircle-waitlist",
"level": "error",
"error": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"message": "\u001b[2m2025-05-17T23:45:23.338Z\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"account": "537639845b3a2365ae57881fbcbd6eee",
"type": "cf-worker",
"fingerprint": "e36b09522b8d83150f98181b2afd807d",
"origin": "fetch",
"messageTemplate": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options.",
"errorTemplate": "\u001b[2m<UTC>\u001b[0m \u001b[31mERROR\u001b[0m \u001b[1m[Better Auth]:\u001b[0m Client Id and Client Secret is required for Google. Make sure to provide them in the options."
},
"links": []
}
Well, progress, now I'm getting this error
2025-05-18T00:23:30.256Z ERROR [Better Auth]: Invalid origin: https://app.safecircle.tech
2025-05-18T00:23:30.256Z ERROR [Better Auth]: Invalid origin: https://app.safecircle.tech
2025-05-18T00:23:30.256Z INFO [Better Auth]: If it's a valid URL, please add https://app.safecircle.tech to trustedOrigins in your auth config
Current list of trustedOrigins: http://localhost:3000
2025-05-18T00:23:30.256Z INFO [Better Auth]: If it's a valid URL, please add https://app.safecircle.tech to trustedOrigins in your auth config
Current list of trustedOrigins: http://localhost:3000
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 2025-05-18T00:41:06.533Z ERROR [Better Auth]: Client Id and Client Secret is required for Google. Make sure to provide them in the options.
Solution
Tresillo
Tresillo4mo ago
Ok, I just needed to add enviroments variable in the runtime options not just in the build configuration
Oreki
Oreki3mo ago
hi, were you able to fix this issue?
Tresillo
TresilloOP3mo ago
Yes
Oreki
Oreki3mo ago
i figured that my environment variables are not loading correctly

Did you find this page helpful?