@@ -42,56 +42,62 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
42
42
emulators : { enabled : true } ,
43
43
} ,
44
44
45
- async setup ( options , nuxt ) {
45
+ async setup ( _options , nuxt ) {
46
46
// ensure provided options are valid
47
- if ( ! options . config ) {
47
+ if ( ! _options . config ) {
48
48
throw new Error (
49
49
'[nuxt-vuefire]: Missing firebase config. Provide a "config" option to the VueFire module options.'
50
50
)
51
51
}
52
52
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
62
54
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 ,
69
63
// ensure the resolved version easier to consume
70
64
emulators : {
71
65
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 : { } ) ,
76
70
} ,
77
71
auth : {
78
72
enabled : isAuthEnabled ,
79
73
// enable session cookie when auth is `true`
80
74
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 : { } ) ,
85
79
} ,
86
80
} satisfies VueFireNuxtModuleOptionsResolved
87
81
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 ) )
91
97
92
98
// we need this to avoid some warnings about missing credentials and ssr
93
99
const emulatorsConfig = await willUseEmulators (
94
- nuxt . options . runtimeConfig . vuefire . options ! ,
100
+ options ,
95
101
resolve ( nuxt . options . rootDir , 'firebase.json' ) ,
96
102
logger
97
103
)
@@ -104,6 +110,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
104
110
105
111
// 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
106
112
// process.env.FIREBASE_CONFIG ||= JSON.stringify(options.config)
113
+ // FIXME: remove deprecation in next release
107
114
if ( typeof options . admin ?. serviceAccount === 'string' ) {
108
115
process . env . GOOGLE_APPLICATION_CREDENTIALS ||=
109
116
options . admin . serviceAccount
@@ -173,12 +180,13 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
173
180
addPluginTemplate ( {
174
181
src : normalize ( resolve ( templatesDir , 'plugin.ejs' ) ) ,
175
182
options : {
183
+ // FIXME: not needed
176
184
...options ,
177
185
ssr : nuxt . options . ssr ,
178
186
} ,
179
187
} )
180
188
181
- if ( options . auth ) {
189
+ if ( _options . auth ) {
182
190
if ( nuxt . options . ssr && ! hasServiceAccount && ! emulatorsConfig ) {
183
191
logger . warn (
184
192
'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>({
188
196
if (
189
197
nuxt . options . ssr &&
190
198
( hasServiceAccount || emulatorsConfig ) &&
191
- resolvedVueFireOptions . auth . sessionCookie
199
+ options . auth . sessionCookie
192
200
) {
193
201
// Add the session handler than mints a cookie for the user
194
202
addServerHandler ( {
@@ -222,19 +230,13 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
222
230
// Emulators must be enabled after the app is initialized but before some APIs like auth.signinWithCustomToken() are called
223
231
224
232
if ( emulatorsConfig ) {
225
- const emulators = detectEmulators (
226
- nuxt . options . runtimeConfig . vuefire . options ! ,
227
- emulatorsConfig ,
228
- logger
229
- )
233
+ const emulators = detectEmulators ( options , emulatorsConfig , logger )
230
234
// add the option to disable the warning. It only exists in Auth
231
235
if ( emulators ?. auth ) {
232
- emulators . auth . options =
233
- nuxt . options . runtimeConfig . vuefire . options ?. emulators ?. auth ?. options
236
+ emulators . auth . options = options . emulators . auth ?. options
234
237
}
235
238
236
239
// expose the detected emulators to the plugins
237
- nuxt . options . runtimeConfig . public . vuefire ??= { }
238
240
nuxt . options . runtimeConfig . public . vuefire . emulators = emulators
239
241
240
242
for ( const serviceName in emulators ) {
@@ -263,7 +265,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
263
265
}
264
266
265
267
if ( hasServiceAccount || emulatorsConfig ) {
266
- if ( resolvedVueFireOptions . auth . sessionCookie ) {
268
+ if ( options . auth . sessionCookie ) {
267
269
// decodes user token from cookie if any
268
270
addPlugin ( resolve ( runtimeDir , 'auth/plugin-user-token.server' ) )
269
271
}
@@ -374,40 +376,40 @@ interface VueFireRuntimeConfig {
374
376
*/
375
377
vuefire ?: {
376
378
/**
377
- * Options passed to the Nuxt VueFire module
379
+ * Firebase Admin SDK Options passed to the Nuxt VueFire module
378
380
* @internal
379
381
*/
380
- options ?: VueFireNuxtModuleOptionsResolved
382
+ admin ?: VueFireNuxtModuleOptionsResolved [ 'admin' ]
381
383
}
382
384
}
383
385
384
386
interface VueFirePublicRuntimeConfig {
387
+ /**
388
+ * Public Runtime config for the VueFire module.
389
+ */
385
390
vuefire ?: {
386
391
/**
387
392
* Emulators to enable.
388
393
*
389
394
* @internal
390
395
*/
391
396
emulators ?: FirebaseEmulatorsToEnable
392
- }
393
- }
394
397
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
401
403
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
+ }
407
410
}
408
411
409
412
declare module '@nuxt/schema' {
410
- export interface AppConfig extends VueFireAppConfig { }
411
413
export interface RuntimeConfig extends VueFireRuntimeConfig { }
412
414
export interface PublicRuntimeConfig extends VueFirePublicRuntimeConfig { }
413
415
}
0 commit comments