Skip to content

Commit 22938c7

Browse files
committed
feat: resolve service account path from env variable
1 parent f6d87dc commit 22938c7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/nuxt/playground/nuxt.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export default defineNuxtConfig({
4242
},
4343

4444
admin: {
45-
serviceAccount: resolve(
46-
fileURLToPath(new URL('./service-account.json', import.meta.url))
47-
),
45+
// serviceAccount: resolve(
46+
// fileURLToPath(new URL('./service-account.json', import.meta.url))
47+
// ),
4848
},
4949
},
5050
],

packages/nuxt/src/module.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
createResolver,
99
defineNuxtModule,
1010
} from '@nuxt/kit'
11-
import type { NuxtModule } from '@nuxt/schema'
1211
// cannot import from firebase/app because the build fails, maybe a nuxt bug?
1312
import type { FirebaseApp, FirebaseOptions } from '@firebase/app-types'
1413
import type {
@@ -114,6 +113,18 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
114113
typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === 'string' &&
115114
process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0
116115

116+
// resolve the credentials in case of monorepos and other projects started from a different folder
117+
if (
118+
typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === 'string' &&
119+
process.env.GOOGLE_APPLICATION_CREDENTIALS?.[0] !== '{'
120+
) {
121+
const resolvedCredentials = resolve(
122+
nuxt.options.rootDir,
123+
process.env.GOOGLE_APPLICATION_CREDENTIALS
124+
)
125+
process.env.GOOGLE_APPLICATION_CREDENTIALS = resolvedCredentials
126+
}
127+
117128
// NOTE: the order of the plugins is reversed, so we end by adding the app plugin which is used by all other
118129
// plugins
119130

0 commit comments

Comments
 (0)