@@ -42,56 +42,62 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
4242 emulators : { enabled : true } ,
4343 } ,
4444
45- async setup ( options , nuxt ) {
45+ async setup ( _options , nuxt ) {
4646 // ensure provided options are valid
47- if ( ! options . config ) {
47+ if ( ! _options . config ) {
4848 throw new Error (
4949 '[nuxt-vuefire]: Missing firebase config. Provide a "config" option to the VueFire module options.'
5050 )
5151 }
5252
53- const { resolve } = createResolver ( import . meta. url )
54- const runtimeDir = fileURLToPath ( new URL ( './runtime' , import . meta. url ) )
55- const templatesDir = fileURLToPath ( new URL ( '../templates' , import . meta. url ) )
56-
57- // TODO: I don't think the appConfig is the right place to store these as it makes things reactive
58- // Let plugins and the user access the firebase config within the app
59- nuxt . options . appConfig . firebaseConfig = markRaw ( options . config )
60- nuxt . options . appConfig . vuefireOptions = markRaw ( options )
61-
53+ // resolve options
6254 const isAuthEnabled =
63- typeof options . auth === 'object'
64- ? options . auth . enabled ?? true // allows user to comment out enabled: false
65- : ! ! options . auth
66-
67- const resolvedVueFireOptions = {
68- ...options ,
55+ typeof _options . auth === 'object'
56+ ? _options . auth . enabled ?? true // allows user to comment out enabled: false
57+ : ! ! _options . auth
58+
59+ const options = {
60+ ..._options ,
61+ // NOTE: TS complains otherwise
62+ config : _options . config ,
6963 // ensure the resolved version easier to consume
7064 emulators : {
7165 enabled :
72- typeof options . emulators === 'object'
73- ? options . emulators . enabled ?? true // allows user to comment out enabled: false
74- : ! ! options . emulators ,
75- ...( typeof options . emulators === 'object' ? options . emulators : { } ) ,
66+ typeof _options . emulators === 'object'
67+ ? _options . emulators . enabled ?? true // allows user to comment out enabled: false
68+ : ! ! _options . emulators ,
69+ ...( typeof _options . emulators === 'object' ? _options . emulators : { } ) ,
7670 } ,
7771 auth : {
7872 enabled : isAuthEnabled ,
7973 // enable session cookie when auth is `true`
8074 sessionCookie :
81- typeof options . auth === 'object'
82- ? isAuthEnabled && options . auth . sessionCookie // deactivating auth also deactivates the session cookie
83- : ! ! options . auth , // fallback to the boolean value of options.auth
84- ...( typeof options . auth === 'object' ? options . auth : { } ) ,
75+ typeof _options . auth === 'object'
76+ ? isAuthEnabled && _options . auth . sessionCookie // deactivating auth also deactivates the session cookie
77+ : ! ! _options . auth , // fallback to the boolean value of options.auth
78+ ...( typeof _options . auth === 'object' ? _options . auth : { } ) ,
8579 } ,
8680 } satisfies VueFireNuxtModuleOptionsResolved
8781
88- nuxt . options . runtimeConfig . vuefire = {
89- options : resolvedVueFireOptions ,
90- }
82+ nuxt . options . runtimeConfig . public . vuefire ??= { }
83+ // avoid any nested reactivity as it's not needed
84+ markRaw ( nuxt . options . runtimeConfig . public . vuefire )
85+ // Let plugins and the user access the firebase config within the app
86+ nuxt . options . runtimeConfig . public . vuefire . config = _options . config
87+ nuxt . options . runtimeConfig . public . vuefire . appCheck = options . appCheck
88+
89+ nuxt . options . runtimeConfig . vuefire ??= { }
90+ markRaw ( nuxt . options . runtimeConfig . vuefire )
91+ nuxt . options . runtimeConfig . vuefire . admin ??= options . admin
92+
93+ // configure transpilation
94+ const { resolve } = createResolver ( import . meta. url )
95+ const runtimeDir = fileURLToPath ( new URL ( './runtime' , import . meta. url ) )
96+ const templatesDir = fileURLToPath ( new URL ( '../templates' , import . meta. url ) )
9197
9298 // we need this to avoid some warnings about missing credentials and ssr
9399 const emulatorsConfig = await willUseEmulators (
94- nuxt . options . runtimeConfig . vuefire . options ! ,
100+ options ,
95101 resolve ( nuxt . options . rootDir , 'firebase.json' ) ,
96102 logger
97103 )
@@ -104,6 +110,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
104110
105111 // This one is set by servers, we set the GOOGLE_APPLICATION_CREDENTIALS env variable instead that has a lower priority and can be both a path or a JSON string
106112 // process.env.FIREBASE_CONFIG ||= JSON.stringify(options.config)
113+ // FIXME: remove deprecation in next release
107114 if ( typeof options . admin ?. serviceAccount === 'string' ) {
108115 process . env . GOOGLE_APPLICATION_CREDENTIALS ||=
109116 options . admin . serviceAccount
@@ -173,12 +180,13 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
173180 addPluginTemplate ( {
174181 src : normalize ( resolve ( templatesDir , 'plugin.ejs' ) ) ,
175182 options : {
183+ // FIXME: not needed
176184 ...options ,
177185 ssr : nuxt . options . ssr ,
178186 } ,
179187 } )
180188
181- if ( options . auth ) {
189+ if ( _options . auth ) {
182190 if ( nuxt . options . ssr && ! hasServiceAccount && ! emulatorsConfig ) {
183191 logger . warn (
184192 'You activated both SSR and auth but you are not providing a service account for the admin SDK. See https://vuefire.vuejs.org/nuxt/getting-started.html#configuring-the-admin-sdk.'
@@ -188,7 +196,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
188196 if (
189197 nuxt . options . ssr &&
190198 ( hasServiceAccount || emulatorsConfig ) &&
191- resolvedVueFireOptions . auth . sessionCookie
199+ options . auth . sessionCookie
192200 ) {
193201 // Add the session handler than mints a cookie for the user
194202 addServerHandler ( {
@@ -222,19 +230,13 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
222230 // Emulators must be enabled after the app is initialized but before some APIs like auth.signinWithCustomToken() are called
223231
224232 if ( emulatorsConfig ) {
225- const emulators = detectEmulators (
226- nuxt . options . runtimeConfig . vuefire . options ! ,
227- emulatorsConfig ,
228- logger
229- )
233+ const emulators = detectEmulators ( options , emulatorsConfig , logger )
230234 // add the option to disable the warning. It only exists in Auth
231235 if ( emulators ?. auth ) {
232- emulators . auth . options =
233- nuxt . options . runtimeConfig . vuefire . options ?. emulators ?. auth ?. options
236+ emulators . auth . options = options . emulators . auth ?. options
234237 }
235238
236239 // expose the detected emulators to the plugins
237- nuxt . options . runtimeConfig . public . vuefire ??= { }
238240 nuxt . options . runtimeConfig . public . vuefire . emulators = emulators
239241
240242 for ( const serviceName in emulators ) {
@@ -263,7 +265,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
263265 }
264266
265267 if ( hasServiceAccount || emulatorsConfig ) {
266- if ( resolvedVueFireOptions . auth . sessionCookie ) {
268+ if ( options . auth . sessionCookie ) {
267269 // decodes user token from cookie if any
268270 addPlugin ( resolve ( runtimeDir , 'auth/plugin-user-token.server' ) )
269271 }
@@ -374,40 +376,40 @@ interface VueFireRuntimeConfig {
374376 */
375377 vuefire ?: {
376378 /**
377- * Options passed to the Nuxt VueFire module
379+ * Firebase Admin SDK Options passed to the Nuxt VueFire module
378380 * @internal
379381 */
380- options ?: VueFireNuxtModuleOptionsResolved
382+ admin ?: VueFireNuxtModuleOptionsResolved [ 'admin' ]
381383 }
382384}
383385
384386interface VueFirePublicRuntimeConfig {
387+ /**
388+ * Public Runtime config for the VueFire module.
389+ */
385390 vuefire ?: {
386391 /**
387392 * Emulators to enable.
388393 *
389394 * @internal
390395 */
391396 emulators ?: FirebaseEmulatorsToEnable
392- }
393- }
394397
395- interface VueFireAppConfig {
396- /**
397- * Firebase config to initialize the app.
398- * @internal
399- */
400- firebaseConfig : FirebaseOptions
398+ /**
399+ * Firebase config to initialize the app.
400+ * @internal
401+ */
402+ config ?: FirebaseOptions
401403
402- /**
403- * VueFireNuxt options used within plugins.
404- * @internal
405- */
406- vuefireOptions : Pick < VueFireNuxtModuleOptions , 'appCheck' | 'auth' >
404+ /**
405+ * AppCheck options.
406+ * @internal
407+ */
408+ appCheck ?: VueFireNuxtModuleOptionsResolved [ 'appCheck' ]
409+ }
407410}
408411
409412declare module '@nuxt/schema' {
410- export interface AppConfig extends VueFireAppConfig { }
411413 export interface RuntimeConfig extends VueFireRuntimeConfig { }
412414 export interface PublicRuntimeConfig extends VueFirePublicRuntimeConfig { }
413415}
0 commit comments