Is Better Auth edge compatible?

I'm trying to deploy my nextjs-hono-backend application on cloudflare pages. It builds successfully but on preview, it returns the following errors in the terminal
✨ Compiled Worker successfully
✨ Parsed 1 valid header rule.
Using vars defined in .dev.vars
⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:8788

✘ [ERROR] Better Auth:error INTERNAL_SERVER_ERROR NeonDbError: Error connecting to database: XMLHttpRequest is not defined

...

✘ [ERROR] Better Auth:error INTERNAL_SERVER_ERROR [f [BetterCallAPIError]: API Error: INTERNAL_SERVER_ERROR Failed to get session] {

status: 'INTERNAL_SERVER_ERROR',
headers: Headers(0) { [immutable]: false },
body: { message: 'Failed to get session', code: 'FAILED_TO_GET_SESSION' },
[cause]: { message: 'Failed to get session', code: 'FAILED_TO_GET_SESSION' }
}

[wrangler:inf] GET /api/auth/get-session 500 Internal Server Error (153ms)
[wrangler:inf] GET / 200 OK (194ms)

✘ [ERROR] ReferenceError: XMLHttpRequest is not defined

[wrangler:inf] GET /favicon-32x32.png 200 OK (20ms)
[wrangler:inf] GET /site.webmanifest 500 Internal Server Error (24ms)
✘ [ERROR] ReferenceError: XMLHttpRequest is not defined

[wrangler:inf] GET / 500 Internal Server Error (23ms)
✘ [ERROR] ReferenceError: XMLHttpRequest is not defined
✨ Compiled Worker successfully
✨ Parsed 1 valid header rule.
Using vars defined in .dev.vars
⎔ Starting local server...
[wrangler:inf] Ready on http://localhost:8788

✘ [ERROR] Better Auth:error INTERNAL_SERVER_ERROR NeonDbError: Error connecting to database: XMLHttpRequest is not defined

...

✘ [ERROR] Better Auth:error INTERNAL_SERVER_ERROR [f [BetterCallAPIError]: API Error: INTERNAL_SERVER_ERROR Failed to get session] {

status: 'INTERNAL_SERVER_ERROR',
headers: Headers(0) { [immutable]: false },
body: { message: 'Failed to get session', code: 'FAILED_TO_GET_SESSION' },
[cause]: { message: 'Failed to get session', code: 'FAILED_TO_GET_SESSION' }
}

[wrangler:inf] GET /api/auth/get-session 500 Internal Server Error (153ms)
[wrangler:inf] GET / 200 OK (194ms)

✘ [ERROR] ReferenceError: XMLHttpRequest is not defined

[wrangler:inf] GET /favicon-32x32.png 200 OK (20ms)
[wrangler:inf] GET /site.webmanifest 500 Internal Server Error (24ms)
✘ [ERROR] ReferenceError: XMLHttpRequest is not defined

[wrangler:inf] GET / 500 Internal Server Error (23ms)
✘ [ERROR] ReferenceError: XMLHttpRequest is not defined
I dont know if neon is making these XMLHttpRequest or better-auth but since neon is edge compatible, it might be better-auth
6 Replies
daveycodez
daveycodez2mo ago
I tried using the auth endpoints on Vercel Edge but I had issues with the JWKS plugin, not sure... But it would be great to support edge for sure
Dev
DevOP2mo ago
@bekacru any advice?
bekacru
bekacru2mo ago
what framework are you using?
Dev
DevOP2mo ago
nextjs with hono as backend in place of default file based routes
bekacru
bekacru2mo ago
I don't think XMLHttpRequest is not defined is thrown from better auth. It's thrown from the neon db adapter.
Dev
DevOP2mo ago
okay, thanks

Did you find this page helpful?