How to access to binding variables during nextjs build process?

I'm trying to user D1 with drizzle orm in next js, currently using next auth 5, and using drizzle adapter for that.. How to get the DB instance during build? export const { handlers: { GET, POST }, auth, signIn, signOut, } = NextAuth({ adapter: DrizzleAdapter(getDBInstance()), providers: [ GoogleProvider({ clientId: process.env.GOOGLE_CLIENT_ID ?? "", clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "", }), ], }); This is method to get db instance export const getDBInstance = () => { console.log("getRequestContext", getRequestContext); const DB = getRequestContext().env.AI_FORM_GENERATOR_DB; return drizzle(DB, { schema }); }; How to get access to Binding variable AI_FORM_GENERATOR_DB during build process?
10 Replies
Hello, I’m Allie!
Only Environment Variables and Secrets are available in the build process atm. You don't have access to any other bindings
kalaivanan
kalaivanan5mo ago
adapter: DrizzleAdapter(getDBInstance()). I need DB instance during build process, is there any alternative way of achieving this?
Hello, I’m Allie!
There is not, no.
kalaivanan
kalaivanan5mo ago
Auth.js | D1
Authentication for the Web
Hello, I’m Allie!
What do you mean? The NextAuth function is called at runtime, when the DB Instance exists
kalaivanan
kalaivanan5mo ago
adapter: D1Adapter(env.db). what is this env.db? Where and how to set this env.db?
Hello, I’m Allie!
That is a D1Database binding that is available at runtime. You can add bindings via the Pages Dashboard, or with a wrangler.toml file
kalaivanan
kalaivanan5mo ago
I dont know why but, it is trying to access during build time in my nextjs app
export const runtime = "edge";
export { GET, POST } from "@/auth";
export const runtime = "edge";
export { GET, POST } from "@/auth";
Im using GET and POST in [...nextauth].route.ts that are returned from NextAuth So during build process, it is trying to get DB instance
Hello, I’m Allie!
Yeah, not quite sure why that would be. I haven't worked much with Next, might be worthwhile to crosspost that it is being run during build in #next-on-pages
kalaivanan
kalaivanan5mo ago
Thanks a lot
Want results from more Discord servers?
Add your server