Skip to content

feat: allow using service account with environment variables #1319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 2 additions & 4 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
createResolver,
defineNuxtModule,
} from '@nuxt/kit'
import type { NuxtModule } from '@nuxt/schema'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import was unused

// cannot import from firebase/app because the build fails, maybe a nuxt bug?
import type { FirebaseApp, FirebaseOptions } from '@firebase/app-types'
import type {
Expand All @@ -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 {
/**
Expand Down Expand Up @@ -108,9 +108,7 @@ export default defineNuxtModule<VueFireNuxtModuleOptions>({
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
Expand Down
23 changes: 23 additions & 0 deletions packages/nuxt/src/runtime/config.ts
Original file line number Diff line number Diff line change
@@ -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
}