stu
stu
Explore posts from servers
BABetter Auth
Created by bitangel84 on 4/16/2025 in #help
Drizzle + PG + Hyperdrive + Cloudflare Workers doesn't work
Could you get Better Auth working with a Hyperdrive connection? Been struggling with it for a while, and gave up. I'm using Postgres, and using the postgres connection string rather than the hyperdrive connection string ended up working for me, but it's not ideal.
22 replies
CDCloudflare Developers
Created by stu on 4/13/2025 in #general-help
Hostname 'www.<my-domain>.com' already has externally managed DNS records
Following up on this, I deleted my A records and CNAME for www. Then deployed with the route pattern "<my-domain>.com". This worked. I'd like to redirect everything to www, but can't seem to get it working correctly.
2 replies
CDCloudflare Developers
Created by JacobMGEvans on 4/13/2025 in #wrangler
Do you already have a Record (CNAME or A
Maybe those rules I previously setup are interfering with the wrangler routes
6 replies
CDCloudflare Developers
Created by JacobMGEvans on 4/13/2025 in #wrangler
Do you already have a Record (CNAME or A
Regarding the www, there is a "Rules" section where I added two template rules. One Redirect from HTTP to HTTPS [Template] URI Full wildcard r"http://*" 301 redirect and Redirect from Root to WWW [Template] URI Full wildcard r"https://<my-domain>.com/*" 301 redirect . And it seems like when I navigate to the DNS area, it has like
CNAME
www
<my-domain>.com
Proxied
CNAME
www
<my-domain>.com
Proxied
6 replies
CDCloudflare Developers
Created by JacobMGEvans on 4/13/2025 in #wrangler
Do you already have a Record (CNAME or A
No description
6 replies
BABetter Auth
Created by stu on 4/13/2025 in #help
Hanging timeout server-side requests using Cloudflare Hyperdrive
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.
7 replies
BABetter Auth
Created by dimsumham on 4/3/2025 in #help
cloudflare error
Amazing, thanks. Yes, the hyperdrive connection string has postgresql:// at the beginning. It's working in other instances, for example to fetch data. But it's getting stuck specifically with better-auth requests I think.
30 replies
BABetter Auth
Created by dimsumham on 4/3/2025 in #help
cloudflare error
hey @dimsumham, was curious if you had success using Cloudflare + Hyperdrive + better-auth? Basically, I have sign-in functionality server-side like:
const result = await auth(env).api.signInEmail({
body: {
email: email.toString(),
password: password.toString(),
},
asResponse: true,
});
const result = await auth(env).api.signInEmail({
body: {
email: email.toString(),
password: password.toString(),
},
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;
}
Any ideas the changes I should make?
30 replies
CDCloudflare Developers
Created by Emilio on 4/10/2025 in #hyperdrive
If you were able to create the
If I replace the hyperdrive connection string with the DB connection string in my code, it works and logs come through.
3 replies
CDCloudflare Developers
Created by Emilio on 4/10/2025 in #hyperdrive
If you were able to create the
Hey @Emilio thanks for the response. That's good to know. I'm trying to query it in my code, and it just hangs and never returns anything. I'm trying to tail the logs for the worker, and not getting any messages. Any suggestions on how to debug this?
3 replies
BABetter Auth
Created by dimsumham on 4/3/2025 in #help
cloudflare error
Nice, I'm new to Cloudflare, so just trying to get things working. I'll look into Hyperdrive, sounds like a good fit for using Postgres with Cloudflare.
30 replies
BABetter Auth
Created by dimsumham on 4/3/2025 in #help
cloudflare error
Hey @dimsumham I'm getting the same error. Did you find any clean way to resolve, or should I wrap auth in a function? I'm also using postgres.
30 replies
BABetter Auth
Created by stu on 4/2/2025 in #help
Invalid token on resetPassword
Thanks for the response, I'm not fully following the flow here. Let's say the token generated and in sendResetPassword is ABC. The URL generated is /reset-password/ABC?callbackURL=/dashboard (maybe my use of callbackURL is incorrect?). By clicking this link the email, it navigates to https://localhost:4321/reset-password/ABC?callbackURL=/dashboard, where I have a form to set a new password. When submitting the form, we parse the token ABC. And then, for testing, checking
ctx.internalAdapter.findVerificationValue(
`reset-password:${token}`
);
ctx.internalAdapter.findVerificationValue(
`reset-password:${token}`
);
, which is finding a row with the correct user. But then passing this same token to resetPassword, I'm getting an INVALID_TOKEN error.
17 replies
BABetter Auth
Created by stu on 4/2/2025 in #help
Invalid token on resetPassword
Digging into this more, it's a bit odd.
const ctx = await auth.$context;
const verificationVal = await ctx.internalAdapter.findVerificationValue(
`reset-password:${token}`
);
const ctx = await auth.$context;
const verificationVal = await ctx.internalAdapter.findVerificationValue(
`reset-password:${token}`
);
If I add this to my Astro page on load, it finds the correct row with the matching user id. I use the same token in the resetPassword body, which fails.
17 replies
BABetter Auth
Created by stu on 4/2/2025 in #help
Invalid token on resetPassword
import { auth } from "../../../lib/auth";

const { token } = Astro.params;

if (!token) {
return Astro.redirect("/signin");
}

if (Astro.request.method === "POST") {

const data = await Astro.request.formData();
const password = data.get("password")?.toString();

if (!password || password?.length < 6) {
return Astro.redirect("/reset-password?error=1");
}

try {

const result = await auth.api.resetPassword({
body: {
newPassword: password,
token,
},
});

Astro.redirect("/signin");
} catch (error) {
return Astro.redirect("/reset-password?error=1");
}
}
import { auth } from "../../../lib/auth";

const { token } = Astro.params;

if (!token) {
return Astro.redirect("/signin");
}

if (Astro.request.method === "POST") {

const data = await Astro.request.formData();
const password = data.get("password")?.toString();

if (!password || password?.length < 6) {
return Astro.redirect("/reset-password?error=1");
}

try {

const result = await auth.api.resetPassword({
body: {
newPassword: password,
token,
},
});

Astro.redirect("/signin");
} catch (error) {
return Astro.redirect("/reset-password?error=1");
}
}
17 replies
BABetter Auth
Created by stu on 4/2/2025 in #help
Invalid token on resetPassword
I'm doing it server side, simply const { token } = Astro.params; That parses the token from the URL, structured like /reset-password/<token>. It looks to be logging the same value that's generated in sendResetPassword.
17 replies
BABetter Auth
Created by stu on 4/2/2025 in #help
Invalid token on resetPassword
Yeah, not sure if I'm misunderstanding the flow or something. Using the exact token that is generated.
17 replies
BABetter Auth
Created by stu on 4/2/2025 in #help
Invalid token on resetPassword
Was going crazy thinking I misconfigured something haha
17 replies