Skip to content

Commit 8c45d44

Browse files
committed
refactor(nuxt): always add the plugin
1 parent a1d2f1a commit 8c45d44

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

packages/nuxt/src/module.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { type NuxtModule } from '@nuxt/schema'
55
import { type FirebaseOptions } from '@firebase/app-types'
66

77
export interface VueFireNuxtModuleOptions {
8-
optionsApiPlugin: boolean
8+
/**
9+
* Should we add the `VueFireFirestoreOptionsAPI` and `VueFireRealtimeDatabaseOptionsAPI` modules?. Pass `true` to add
10+
* both, or `'firestore'` or `'realtime-database'` to add only one. Pass false to disable.
11+
* @default false
12+
*/
13+
optionsApiPlugin?: boolean | 'firestore' | 'database'
914

1015
config: FirebaseOptions
1116
/**
@@ -39,11 +44,9 @@ const VueFireModule: NuxtModule<VueFireNuxtModuleOptions> =
3944

4045
setup(options, nuxt) {
4146
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
42-
if (options.optionsApiPlugin) {
43-
nuxt.options.build.transpile.push(runtimeDir)
44-
// TODO: check for individual options
45-
addPlugin(resolve(runtimeDir, 'plugin'))
46-
}
47+
nuxt.options.build.transpile.push(runtimeDir)
48+
// TODO: check for individual options
49+
addPlugin(resolve(runtimeDir, 'plugin'))
4750
},
4851
})
4952

packages/nuxt/src/runtime/plugin.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { usePendingPromises, VueFire, useSSRInitialState } from 'vuefire'
22
import { initializeApp } from 'firebase/app'
3-
import { defineNuxtPlugin } from '#imports'
3+
import { defineNuxtPlugin, useAppConfig } from '#imports'
44

55
export default defineNuxtPlugin(async (nuxtApp) => {
66
// TODO: initialize firebase app from config
7+
console.log('appconfig', useAppConfig())
78
const firebaseApp = initializeApp()
89

910
nuxtApp.vueApp.use(
@@ -15,20 +16,12 @@ export default defineNuxtPlugin(async (nuxtApp) => {
1516
)
1617

1718
if (process.server) {
18-
await usePendingPromises()
1919
// TODO: pass the firebaseApp
20-
nuxtApp.payload.vuefire = useSSRInitialState()
20+
nuxtApp.payload.vuefire = useSSRInitialState(undefined, firebaseApp)
2121
} else if (nuxtApp.payload?.vuefire) {
2222
// hydrate the plugin state from nuxtApp.payload.vuefire
23-
useSSRInitialState(nuxtApp.payload.vuefire)
23+
useSSRInitialState(nuxtApp.payload.vuefire, firebaseApp)
2424
}
2525

26-
return {
27-
provide: {
28-
// firebaseApp:
29-
// firestore
30-
// database
31-
// auth
32-
},
33-
}
26+
return {}
3427
})

0 commit comments

Comments
 (0)