mihaaai
mihaaai
Explore posts from servers
HHono
Created by mihaaai on 10/16/2024 in #help
Is there a way to get bindings outside the `c` Context of an inbound Request in Cloudflare Workers?
I'm trying to setup the better-auth with D1 but following the guide it pops out that I need to have a valid reference of my binded D1 database outside of the inbount request context (the c.env). There are other examples of using D1 with better-auth but I can't figure out how to make it work within a Hono app deployed on Cloudflare Workers.
import { betterAuth } from "better-auth";
import { anonymous } from "better-auth/plugins";
import { Kysely } from "kysely";
import { D1Dialect } from "kysely-d1";

export const auth = betterAuth({
database: {
db: new Kysely({
dialect: new D1Dialect({
database: process.env.DB as unknown as D1Database, // this results in database: undefined
}),
}),
type: "sqlite",
},
emailAndPassword: {
enabled: true,
},
plugins: [anonymous()],
});
import { betterAuth } from "better-auth";
import { anonymous } from "better-auth/plugins";
import { Kysely } from "kysely";
import { D1Dialect } from "kysely-d1";

export const auth = betterAuth({
database: {
db: new Kysely({
dialect: new D1Dialect({
database: process.env.DB as unknown as D1Database, // this results in database: undefined
}),
}),
type: "sqlite",
},
emailAndPassword: {
enabled: true,
},
plugins: [anonymous()],
});
The configuration file is within /src/lib/auth.ts but isn't called directly nowhere within the Hono app I have a worker-configuration.d.ts in my src directory declaring the DB as a D1Database type, and the wrangler binding as well.
10 replies