Help with OpenNextjs and BetterAuth
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
Nor email or github/google or any oauth works
Trying to visit manually /api/auth/email gets me this error (see screenshot)
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 (see 2nd img)
1 Reply
It appears that it can't access the enviroment variables in the production build. But I've setup them in the build configuration (as in my other opennexjs projects)
{
"source": {
"level": "error",
"message": "\u001b[2m2025-05-16T11:45:52.724Z\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": "01JVCEMG2M4X9DJPJBSCYXWCQ9",
"type": "cf-worker",
"error": "\u001b[2m2025-05-16T11:45:52.724Z\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-16T11:45:52.724Z",
"$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": "80025a77-efe9-4491-902f-a9cef45c712b"
},
"requestId": "940aa19f586dcfe3"
},
"$metadata": {
"id": "01JVCEMG2M4X9DJPJBSCYXWCQ9",
"requestId": "940aa19f586dcfe3",
"trigger": "POST /api/auth/sign-in/social",
"service": "safecircle-waitlist",
"level": "error",
"error": "\u001b[2m2025-05-16T11:45:52.724Z\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-16T11:45:52.724Z\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-16T11:45:52.724Z\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": "01JVCEMG2M4X9DJPJBSCYXWCQ9",
"type": "cf-worker",
"error": "\u001b[2m2025-05-16T11:45:52.724Z\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-16T11:45:52.724Z",
"$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": "80025a77-efe9-4491-902f-a9cef45c712b"
},
"requestId": "940aa19f586dcfe3"
},
"$metadata": {
"id": "01JVCEMG2M4X9DJPJBSCYXWCQ9",
"requestId": "940aa19f586dcfe3",
"trigger": "POST /api/auth/sign-in/social",
"service": "safecircle-waitlist",
"level": "error",
"error": "\u001b[2m2025-05-16T11:45:52.724Z\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-16T11:45:52.724Z\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": []
}

