From f9ddc2fa13cce2cfb0802c39327ec61a9a08cb48 Mon Sep 17 00:00:00 2001 From: Neil Richter Date: Sun, 12 Mar 2023 17:43:03 +0100 Subject: [PATCH 1/2] feat: allow using service account with environment variables --- packages/nuxt/src/module.ts | 6 ++---- packages/nuxt/src/runtime/config.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 packages/nuxt/src/runtime/config.ts diff --git a/packages/nuxt/src/module.ts b/packages/nuxt/src/module.ts index 0aa760fd..23044283 100644 --- a/packages/nuxt/src/module.ts +++ b/packages/nuxt/src/module.ts @@ -8,7 +8,6 @@ import { createResolver, defineNuxtModule, } from '@nuxt/kit' -import type { NuxtModule } from '@nuxt/schema' // cannot import from firebase/app because the build fails, maybe a nuxt bug? import type { FirebaseApp, FirebaseOptions } from '@firebase/app-types' import type { @@ -20,6 +19,7 @@ import { markRaw } from 'vue' import type { NuxtVueFireAppCheckOptions } from './runtime/app-check' import { addMissingAlias } from './firebaseAliases' import { log } from './runtime/logging' +import { isServiceAccountConfigured } from './runtime/config' export interface VueFireNuxtModuleOptions { /** @@ -108,9 +108,7 @@ export default defineNuxtModule({ process.env.GOOGLE_APPLICATION_CREDENTIALS ||= options.admin.serviceAccount } - const hasServiceAccount = - typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === 'string' && - process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0 + const hasServiceAccount = isServiceAccountConfigured(options) // NOTE: the order of the plugins is reversed, so we end by adding the app plugin which is used by all other // plugins diff --git a/packages/nuxt/src/runtime/config.ts b/packages/nuxt/src/runtime/config.ts new file mode 100644 index 00000000..385d611c --- /dev/null +++ b/packages/nuxt/src/runtime/config.ts @@ -0,0 +1,23 @@ +import { VueFireNuxtModuleOptions } from '../module' + +export function isServiceAccountConfigured(options: VueFireNuxtModuleOptions) { + const hasServiceAccountFile = + typeof process.env.GOOGLE_APPLICATION_CREDENTIALS === 'string' && + process.env.GOOGLE_APPLICATION_CREDENTIALS.length > 0 + + if (hasServiceAccountFile) { + return true + } + + if (typeof options.admin?.serviceAccount === 'object') { + if ( + options.admin.serviceAccount.clientEmail?.length && + options.admin.serviceAccount.privateKey?.length && + options.admin.serviceAccount.projectId?.length + ) { + return true + } + } + + return false +} From 6fb142d3da4525ea5383ee82b7b497357a08a4d4 Mon Sep 17 00:00:00 2001 From: Neil Richter Date: Thu, 23 Mar 2023 10:33:26 +0100 Subject: [PATCH 2/2] chore: update package version --- package.json | 4 ++-- packages/nuxt/package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index e183e185..20827c0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "vuefire", - "version": "3.1.0", + "name": "@noook/vuefire", + "version": "3.1.1", "description": "Official Firebase bindings for Vue.js", "packageManager": "pnpm@7.25.1", "type": "module", diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 10b0138d..3773dedd 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -1,7 +1,7 @@ { - "name": "nuxt-vuefire", + "name": "@noook/nuxt-vuefire", "description": "Nuxt.js module for VueFire", - "version": "0.1.6", + "version": "0.1.7", "license": "MIT", "type": "module", "exports": {