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
Only Environment Variables and Secrets are available in the build process atm. You don't have access to any other bindings
adapter: DrizzleAdapter(getDBInstance()). I need DB instance during build process, is there any alternative way of achieving this?
There is not, no.
Auth.js | D1
Authentication for the Web
What do you mean? The
NextAuth
function is called at runtime, when the DB Instance existsadapter: D1Adapter(env.db). what is this env.db?
Where and how to set this env.db?
That is a D1Database binding that is available at runtime. You can add bindings via the Pages Dashboard, or with a
wrangler.toml
fileI dont know why but, it is trying to access during build time in my nextjs app
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
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
Thanks a lot