-
Notifications
You must be signed in to change notification settings - Fork 9
BetterAuth can't query user/session when cloudflare hyperdrive is used #294
Description
Hi 👋🏻
Description
I was facing issue similar to this when using better auth nuxt module.
Cloudflare Logs:
GET https://nuxthub-better-auth-repro.jdsolanki0001.workers.dev/ - Ok @ 25/3/2026, 12:04:21 am
GET https://nuxthub-better-auth-repro.jdsolanki0001.workers.dev/api/auth/get-session - Ok @ 25/3/2026, 12:04:22 am
(error) 2026-03-24T18:34:22.461Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR Error: Failed query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id" from "session" where "session"."token" = $1
params: CfZ7HikYQH641Nxsp4nT6DyuMSb7NMTb
Previously I migrated my main project to NuxtHub + better-auth nuxt module but I was facing same error so I thought I might have misconfigured something because it was large project so I started from scratch and while I reached auth part I'm now facing same thing.
Reproduction
To reproduce this, I created:
Reproduction repo: https://github.com/jd-solanki/nuxthub-better-auth-repro
Steps:
- Fork, clone and ensure it runs fine locally
- Create DB on neon (or supabase or other)
- Create HyperDrive on CF and use direct connection string in setup
- pass/replace HyperDrive id in
nuxt.config.ts(🚨🚨🚨 IMPORTANT) - Ensure following env vars in CF build:
NUXT_BETTER_AUTH_SECRET=<random 32 character string>
DATABASE_URL=<direct connection string from neon/supabase so that migration applies>
- Deploy the project
- Run
npx wrangler tail <worker-name>to see logs in terminal - try
/register,/login&/apppage you may get error like mentioned above that it fails to query
Error:
POST https://nuxthub-better-auth-repro.jdsolanki0001.workers.dev/api/auth/sign-up/email - Ok @ 25/3/2026, 12:19:03 am
(error) 2026-03-24T18:49:03.116Z ERROR [Better Auth]: Error Error: Failed query: select "id", "name", "email", "email_verified", "image", "created_at", "updated_at" from "user" where "user"."email" = $1
params: [email protected]
(error) # SERVER_ERROR: Error: Failed query: select "id", "name", "email", "email_verified", "image", "created_at", "updated_at" from "user" where "user"."email" = $1
params: [email protected]
to logout clean cookies ;)
Note
Sometime you may encounter error "Worker exceeded CPU time limit (503)" so kindly error that assuming it's not related to this issue but I'm not sure though. Have a look for 500 errors
Additional Context
I believe this is due to singleton of betterAuth and I'm not sure if this is handled in this module.
Reference: better-auth/better-auth#969 (comment)
