Skip to content

Commit 6698c04

Browse files
committed
feat: improve ssr + admin check
1 parent c9461ef commit 6698c04

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

packages/nuxt/src/module.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ const VueFire: NuxtModule<VueFireNuxtModuleOptions> =
128128
// plugins
129129

130130
if (options.auth) {
131+
if (nuxt.options.ssr && !hasServiceAccount) {
132+
log(
133+
'warn',
134+
'You activated both SSR and auth but you are not providing an admin config. If you render or prerender any page using auth, you will get an error. To fix this, provide an admin config to the nuxt-vuefire module.'
135+
)
136+
}
137+
131138
addPlugin(resolve(runtimeDir, 'auth/plugin.client'))
132139
// must be added after the admin module to use the admin app
133140
addPlugin(resolve(runtimeDir, 'auth/plugin.server'))
@@ -148,7 +155,15 @@ const VueFire: NuxtModule<VueFireNuxtModuleOptions> =
148155

149156
if (options.appCheck) {
150157
addPlugin(resolve(runtimeDir, 'app-check/plugin.client'))
151-
addPlugin(resolve(runtimeDir, 'app-check/plugin.server'))
158+
if (hasServiceAccount) {
159+
addPlugin(resolve(runtimeDir, 'app-check/plugin.server'))
160+
} else if (nuxt.options.ssr) {
161+
log(
162+
'warn',
163+
'You activated both SSR and app-check but you are not providing an admin config. If you render or prerender any page using app-check, you will get an error. To fix this, provide an admin config to the nuxt-vuefire module.'
164+
// TODO: link about how to provide admin credentials
165+
)
166+
}
152167
}
153168

154169
// this adds the VueFire plugin and handle SSR state serialization and hydration
@@ -165,25 +180,27 @@ const VueFire: NuxtModule<VueFireNuxtModuleOptions> =
165180
addPlugin(resolve(runtimeDir, 'app/plugin.client'))
166181
addPlugin(resolve(runtimeDir, 'app/plugin.server'))
167182

168-
// we start the admin app first so we can have access to the user uid everywhere
169-
// TODO: if options.admin
183+
// we start the admin app before the regular app so we can have access to the user uid everywhere
170184
if (options.admin || nuxt.options.ssr) {
171185
if (!nuxt.options.ssr) {
172186
log(
173187
'warn',
174-
'The "admin" option is only used during SSR. You should reenable ssr to use it.'
188+
'The "admin" option is only used during SSR. You should reenable SSR to use it or remove it if you are not doing SSR or SSG.'
175189
)
176190
}
177191

178192
// TODO: remove this runtime config if it's not needed as it could include sensitive data
179193
if (options.admin) {
180194
nuxt.options.appConfig.firebaseAdmin = markRaw(options.admin)
181195
}
182-
// this plugin adds the user so it's accessible directly in the app as well
183-
if (options.auth) {
184-
addPlugin(resolve(runtimeDir, 'admin/plugin-auth-user.server'))
196+
197+
if (hasServiceAccount) {
198+
// this plugin adds the user so it's accessible directly in the app as well
199+
if (options.auth) {
200+
addPlugin(resolve(runtimeDir, 'admin/plugin-auth-user.server'))
201+
}
202+
addPlugin(resolve(runtimeDir, 'admin/plugin.server'))
185203
}
186-
addPlugin(resolve(runtimeDir, 'admin/plugin.server'))
187204
}
188205

189206
// Add auto imports that are useful to be auto imported

0 commit comments

Comments
 (0)