From b1362bfa73c1797017a8566b30721495c78ec2c0 Mon Sep 17 00:00:00 2001 From: Leandro Narosky Date: Mon, 3 Jun 2024 11:10:35 -0300 Subject: [PATCH] Fix service account for firebase prod. --- .../docs/en/guides/backend/google-firebase.mdx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/content/docs/en/guides/backend/google-firebase.mdx b/src/content/docs/en/guides/backend/google-firebase.mdx index 0eed9a33fef09..669ab4ff1010d 100644 --- a/src/content/docs/en/guides/backend/google-firebase.mdx +++ b/src/content/docs/en/guides/backend/google-firebase.mdx @@ -145,9 +145,19 @@ const serviceAccount = { client_x509_cert_url: import.meta.env.FIREBASE_CLIENT_CERT_URL, }; -export const app = activeApps.length === 0 ? initializeApp({ - credential: cert(serviceAccount as ServiceAccount), -}) : activeApps[0]; +const initApp = () => { + if (import.meta.env.PROD) { + console.info('PROD env detected. Using default service account.') + // Use default config in firebase functions. Should be already injected in the server by Firebase. + return initializeApp() + } + console.info('Loading service account from env.') + return initializeApp({ + credential: cert(serviceAccount as ServiceAccount) + }) +} + +export const app = activeApps.length === 0 ? initApp() : activeApps[0]; ``` :::note