Hanging timeout server-side requests using Cloudflare Hyperdrive

Anyone have success using Cloudflare Hyperdrive with Better-Auth? Basically, I have sign-in functionality server-side like:
const result = await auth(env).api.signInEmail({
body: {
email,
password,
},
asResponse: true,
});
const result = await auth(env).api.signInEmail({
body: {
email,
password,
},
asResponse: true,
});
But it's hanging forever when I hit it. No logs, just forever loading. Auth looks like:
export const auth = (env: Env) =>
betterAuth({
database: {
dialect: new PostgresJSDialect({
postgres: getDb(env), // Call getDb() as a function to create a new connection each time
}),
// dialect,
type: "postgres",
},
emailAndPassword: {
// email and password stuff
},
secret: BETTER_AUTH_SECRET,
});
export const auth = (env: Env) =>
betterAuth({
database: {
dialect: new PostgresJSDialect({
postgres: getDb(env), // Call getDb() as a function to create a new connection each time
}),
// dialect,
type: "postgres",
},
emailAndPassword: {
// email and password stuff
},
secret: BETTER_AUTH_SECRET,
});
And getDb function looks like:
export function getDb(env: Env) {
// Connection URL from environment variables
let connectionString = env.HYPERDRIVE.connectionString;

const sql = postgres(connectionString, {
max: 5,
// idle_timeout: 30,
ssl: import.meta.env.DEV,
// Debug options - remove in production
debug: true,
fetch_types: false,
});

return sql;
}
export function getDb(env: Env) {
// Connection URL from environment variables
let connectionString = env.HYPERDRIVE.connectionString;

const sql = postgres(connectionString, {
max: 5,
// idle_timeout: 30,
ssl: import.meta.env.DEV,
// Debug options - remove in production
debug: true,
fetch_types: false,
});

return sql;
}
If I use the postgres connectionString directly, it works. But if I use the Hyperdrive connectionString, it hangs. Any ideas?
3 Replies
rhitune
rhitune7d ago
why email.tostring it must be string
stu
stuOP6d ago
it's form data. It's a FormDataEntryValue type, and adding toString() turns the value to a string. Will update the code excerpt. I don't think it's an issue there, as this functionality works when I use a regular postgres connectionString, but hangs forever when I use a Hyperdrive connectionString.
bitangel84
bitangel843d ago
better auth and cloudflare hyperdrive doesn't work I also tried @neondatabase/serverless but I ended to get one more error
NeonDbError: Error connecting to database: Network connection lost.
NeonDbError: Error connecting to database: Network connection lost.

Did you find this page helpful?