How to use Lucia with Nuxt Hub ? (error: missing cloudflare db binding)

As the title suggest, I have the following error :
ERROR  [worker reload] [worker init] Missing Cloudflare DB binding (D1)                           11:54:13 PM

  at createError (node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:74:12)
  at hubDatabase (node_modules/.pnpm/@nuxthub+core@0.5.11_ioredis@5.4.1_nuxt@3.11.2_@parcel+watcher@2.4.1_@types+node@20.12.7_@uno_dwp6dcetq7zet4pibimgquizse/node_modules/@nuxthub/core/dist/runtime/server/utils/database.mjs:22:9)
  at useDrizzle (server/utils/drizzle.ts:11:1)
  at <anonymous> (server/utils/drizzle.ts:15:1)
  at ModuleJob.run (node:internal/modules/esm/module_job:235:25)
  at async ModuleLoader.import (node:internal/modules/esm/loader:461:24)
  at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:119:5)


I tried to implement as per the documentation of Lucia, with some changes.
import * as schema from '../database/schema'

export const tables = schema

export function useDrizzle() {
  return drizzle(hubDatabase(), { schema })
}

// the following line is failing 
const adapter = new DrizzleSQLiteAdapter(
  useDrizzle(),
  tables.session,
  tables.user
)

export const lucia = new Lucia(adapter, {
  sessionCookie: {
    attributes: {
      secure: !process.dev,
    },
  },
})


docs:
Definition of hubDatabase() with similar error on line 38 : https://github.com/nuxt-hub/core/blob/main/src/runtime/server/utils/database.ts

reproduction link : https://stackblitz.com/~/github.com/rktmatt/help-drizzle-nuxt-hub
Was this page helpful?