Skip to content

Commit 346ad0d

Browse files
committed
fix: use runtimeconfig for nitro
1 parent 23b3a30 commit 346ad0d

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

src/module.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -233,42 +233,16 @@ export default defineNuxtModule<RuntimeModuleOptions>({
233233
nuxt.hook('nitro:config', async (nitroConfig) => {
234234
nitroConfig.experimental = nitroConfig.experimental || {}
235235
nitroConfig.experimental.database = true
236-
237-
// Configure Nitro database if not already configured by consumer
238-
nitroConfig.database = nitroConfig.database || {}
239-
240-
// Only set default database if not already configured by consumer
241-
if (!nitroConfig.database.default) {
242-
// Use nuxt-users database configuration for Nitro's default database
243-
const finalConnectorConfig = nuxt.options.runtimeConfig.nuxtUsers as ModuleOptions
244-
const connectorOptions = { ...finalConnectorConfig.connector.options }
245-
246-
// Map nuxt-users connector format to Nitro database format
247-
let nitroConnector: 'better-sqlite3' | 'mysql2' | 'postgresql'
248-
switch (finalConnectorConfig.connector.name) {
249-
case 'sqlite':
250-
nitroConnector = 'better-sqlite3'
251-
break
252-
case 'mysql':
253-
nitroConnector = 'mysql2'
254-
break
255-
case 'postgresql':
256-
nitroConnector = 'postgresql'
257-
break
258-
default:
259-
nitroConnector = 'better-sqlite3'
260-
}
261-
262-
nitroConfig.database.default = {
263-
connector: nitroConnector,
264-
options: connectorOptions
265-
}
266-
}
267-
268236
nitroConfig.experimental.tasks = true
237+
269238
// Add tasks directory to scan
270239
nitroConfig.scanDirs = nitroConfig.scanDirs || []
271240
nitroConfig.scanDirs.push(resolver.resolve('./runtime/server/tasks'))
241+
242+
// NOTE: We no longer configure the database connection here at build time
243+
// because it prevents runtime environment variables from being used.
244+
// The database connection is now established at runtime through useDb()
245+
// which properly reads from useRuntimeConfig()
272246
})
273247

274248
// Auto-register all components from the components directory

0 commit comments

Comments
 (0)