88} from '@nuxt/kit'
99import type { NuxtModule } from '@nuxt/schema'
1010import type { FirebaseOptions } from '@firebase/app-types'
11+ import type { AppOptions , ServiceAccount } from 'firebase-admin'
1112import type { NuxtVueFireAppCheckOptions } from './app-check'
1213
1314export interface VueFireNuxtModuleOptions {
@@ -18,15 +19,36 @@ export interface VueFireNuxtModuleOptions {
1819 */
1920 optionsApiPlugin ?: boolean | 'firestore' | 'database'
2021
22+ /**
23+ * Firebase Options passed to `firebase/app`'s `initializeApp()`.
24+ */
2125 config ?: FirebaseOptions
2226
27+ /**
28+ * Firebase Admin Options.
29+ */
30+ admin ?: {
31+ /**
32+ * Firebase Admin Options passed to `firebase-admin`'s `initializeApp()`. Required if you are using the auth, or the
33+ * app-check module.
34+ */
35+ config : Omit < AppOptions , 'credential' >
36+
37+ /**
38+ * Firebase Admin Service Account passed to `firebase-admin`'s `initializeApp()`. Required if you are adding an adminConfig
39+ */
40+ serviceAccount : string | ServiceAccount
41+ }
42+
2343 /**
2444 * Optional name passed to `firebase.initializeApp(config, name)`
2545 */
26- appName ?: string
46+ // TODO: is this useful?
47+ // appName?: string
2748
2849 /**
29- * Enables AppCheck
50+ * Enables AppCheck on the client and server. Note you only need to pass the options for the client, on the server,
51+ * the configuration will be handled automatically.
3052 */
3153 appCheck ?: NuxtVueFireAppCheckOptions
3254
@@ -67,11 +89,25 @@ const VueFire: NuxtModule<VueFireNuxtModuleOptions> =
6789
6890 // Let plugins and the user access the firebase config within the app
6991 nuxt . options . appConfig . firebaseConfig = options . config
70- nuxt . options . appConfig . appCheck = options . appCheck
92+ nuxt . options . appConfig . vuefireOptions = options
7193
7294 // nuxt.options.build.transpile.push(templatesDir)
7395 nuxt . options . build . transpile . push ( runtimeDir )
7496
97+ if ( nuxt . options . ssr && options . admin ) {
98+ // check the provided config is valid
99+ if ( options . auth || options . appCheck ) {
100+ if ( ! options . admin . config || ! options . admin . serviceAccount ) {
101+ throw new Error (
102+ '[VueFire]: Missing firebase "admin" config. Provide an "admin" option to the VueFire module options. This is necessary to use the auth or app-check module.'
103+ )
104+ }
105+ nuxt . options . appConfig . firebaseAdmin = options . admin
106+ }
107+
108+ addPlugin ( resolve ( runtimeDir , '2.admin-plugin.server.ts' ) )
109+ }
110+
75111 nuxt . hook ( 'modules:done' , ( ) => {
76112 // addPlugin(resolve(runtimeDir, 'plugin'))
77113
@@ -101,8 +137,17 @@ declare module '@nuxt/schema' {
101137 firebaseConfig : FirebaseOptions
102138
103139 /**
104- * AppCheck options passed to VueFire module.
140+ * VueFireNuxt options used within plugins.
141+ * @internal
142+ */
143+ vuefireOptions : Pick < VueFireNuxtModuleOptions , 'appCheck' | 'auth' >
144+
145+ /**
146+ * Firebase Admin options passed to VueFire module. Only available on the server.
105147 */
106- appCheck ?: NuxtVueFireAppCheckOptions
148+ firebaseAdmin ?: {
149+ config : Omit < AppOptions , 'credential' >
150+ serviceAccount : string | ServiceAccount
151+ }
107152 }
108153}
0 commit comments