-
Notifications
You must be signed in to change notification settings - Fork 8
Closed
Description
Bug Description
When secondaryStorage: true is enabled in nuxt.config, the generated .nuxt/better-auth/secondary-storage.mjs file contains a top-level import:
import { kv } from 'hub:kv'This causes a build error because the hub:kv virtual module is not available at module evaluation time:
Error: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'hub:'
Steps to Reproduce
- Install
@onmax/nuxt-better-authand@nuxthub/core - Configure nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@onmax/nuxt-better-auth'],
hub: { kv: true, db: true },
auth: { secondaryStorage: true }
})- Run
npm run dev - Navigate to any page
Expected Behavior
The kv auto-import from NuxtHub should work without errors.
Root Cause
In src/module.ts, the generated code uses a top-level import:
const secondaryStorageCode = secondaryStorageEnabled
? \`import { kv } from 'hub:kv' // ❌ Top-level import
export function createSecondaryStorage() { ... }\`Proposed Fix
Since NuxtHub auto-imports kv on the server side, the import statement can be removed entirely:
const secondaryStorageCode = secondaryStorageEnabled
? \`export function createSecondaryStorage() {
return {
get: async (key) => kv.get(\\`_auth:\\${key}\\`), // ✅ Use auto-import
set: async (key, value, ttl) => kv.set(\\`_auth:\\${key}\\`, value, { ttl }),
delete: async (key) => kv.del(\\`_auth:\\${key}\\`),
}
}\`Alternatively, use the alias that was already resolved:
const hubKvPath = nuxt.options.alias['hub:kv']
const secondaryStorageCode = secondaryStorageEnabled && hubKvPath
? \`import { kv } from '${hubKvPath}' // ✅ Use resolved alias
export function createSecondaryStorage() { ... }\`Environment
@onmax/nuxt-better-auth: 0.0.2-alpha.3@nuxthub/core: 0.10.4- Nuxt: 4.2.2
Workaround
Disable secondary storage:
auth: { secondaryStorage: false }Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels