Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
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
}