Skip to content

Commit 76c8b21

Browse files
committed
feat(app-check): disable with emulators and no service account
1 parent d02852f commit 76c8b21

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

packages/nuxt/src/module.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,34 +112,44 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
112112
// plugins
113113

114114
if (options.appCheck) {
115-
if (
116-
process.env.FIREBASE_APPCHECK_DEBUG_TOKEN &&
117-
// only use the debug token if the user explicitly set debug to true or if nothing was provided and we are not in production
118-
(options.appCheck.debug === true ||
119-
// allow a manual override from the console before bundling
120-
process.env.VUEFIRE_APPCHECK_DEBUG ||
121-
(options.appCheck.debug == null &&
122-
process.env.NODE_ENV !== 'production'))
123-
) {
124-
logger.debug(
125-
`Using app check debug token from env variable "${process.env.FIREBASE_APPCHECK_DEBUG_TOKEN}"`
115+
if (!process.env.GOOGLE_APPLICATION_CREDENTIALS && emulatorsConfig) {
116+
logger.info(
117+
'Disabling App Check in the context of emulators as no "GOOGLE_APPLICATION_CREDENTIALS" env variable was defined.'
126118
)
127-
if (process.env.NODE_ENV === 'production' && options.appCheck.debug) {
119+
} else {
120+
if (
121+
process.env.FIREBASE_APPCHECK_DEBUG_TOKEN &&
122+
// only use the debug token if the user explicitly set debug to true or if nothing was provided and we are not in production
123+
(options.appCheck.debug === true ||
124+
// allow a manual override from the console before bundling
125+
process.env.VUEFIRE_APPCHECK_DEBUG ||
126+
(options.appCheck.debug == null &&
127+
process.env.NODE_ENV !== 'production'))
128+
) {
129+
logger.debug(
130+
`Using app check debug token from env variable "${process.env.FIREBASE_APPCHECK_DEBUG_TOKEN}"`
131+
)
132+
if (process.env.NODE_ENV === 'production' && options.appCheck.debug) {
133+
logger.warn(
134+
'You are using a debug token in production, DO NOT DEPLOY THIS BUILD. If you do, you will leak your debug app check token.'
135+
)
136+
}
137+
options.appCheck.debug = process.env.FIREBASE_APPCHECK_DEBUG_TOKEN
138+
} else if (emulatorsConfig) {
139+
logger.debug('Detected Emulators environment, using debug App Check')
140+
options.appCheck.debug ??= true
141+
}
142+
143+
addPlugin(resolve(runtimeDir, 'app-check/plugin.client'))
144+
// TODO: With emulators a different plugin should be used, one that doesn't instantiate app check as it will error on the server anyway
145+
if (hasServiceAccount || emulatorsConfig) {
146+
// this is needed by the api endpoint to properly work if no service account is provided, otherwise, the projectId is within the service account
147+
addPlugin(resolve(runtimeDir, 'app-check/plugin.server'))
148+
} else if (nuxt.options.ssr && !emulatorsConfig) {
128149
logger.warn(
129-
'You are using a debug token in production, DO NOT DEPLOY THIS BUILD. If you do, you will leak your debug app check token.'
150+
'You activated both SSR and app-check 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.'
130151
)
131152
}
132-
options.appCheck.debug = process.env.FIREBASE_APPCHECK_DEBUG_TOKEN
133-
}
134-
addPlugin(resolve(runtimeDir, 'app-check/plugin.client'))
135-
// TODO: With emulators a different plugin should be used, one that doesn't instantiate app check as it will error on the server anyway
136-
if (hasServiceAccount || emulatorsConfig) {
137-
// this is needed by the api endpoint to properly work if no service account is provided, otherwise, the projectId is within the service account
138-
addPlugin(resolve(runtimeDir, 'app-check/plugin.server'))
139-
} else if (nuxt.options.ssr && !emulatorsConfig) {
140-
logger.warn(
141-
'You activated both SSR and app-check 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.'
142-
)
143153
}
144154
}
145155

0 commit comments

Comments
 (0)