diff --git a/contributors.yml b/contributors.yml index 280d0143a7f..e678df34be8 100644 --- a/contributors.yml +++ b/contributors.yml @@ -275,6 +275,7 @@ - pacexy - pcattori - penspinner +- penx - phishy - plastic041 - princerajroy diff --git a/examples/firebase-auth-firestore/app/server/firebase.server.ts b/examples/firebase-auth-firestore/app/server/firebase.server.ts index e5ad1a0fc4a..b0465789774 100644 --- a/examples/firebase-auth-firestore/app/server/firebase.server.ts +++ b/examples/firebase-auth-firestore/app/server/firebase.server.ts @@ -1,15 +1,40 @@ -import admin from "firebase-admin/app"; -import client from "firebase/app"; +import { + getApps as getServerApps, + initializeApp as initializeServerApp, + cert as serverCert, +} from "firebase-admin/app"; +import { + getApps as getClientApps, + initializeApp as initializeClientApp, +} from "firebase/app"; import { getAuth as getServerAuth } from "firebase-admin/auth"; import { getAuth as getClientAuth } from "firebase/auth"; -if (client.getApps().length === 0) { - client.initializeApp(JSON.parse(process.env.CLIENT_CONFIG as string)); +if (getClientApps().length === 0) { + if (!process.env.CLIENT_CONFIG) { + throw new Error("Missing CLIENT_CONFIG environment variable"); + } + let config; + try { + config = JSON.parse(process.env.CLIENT_CONFIG); + } catch { + throw Error("Invalid CLIENT_CONFIG environment variable"); + } + initializeClientApp(config); } -if (admin.getApps().length === 0) { - admin.initializeApp({ - credential: admin.cert(JSON.parse(process.env.SERVICE_ACCOUNT as string)), +if (getServerApps().length === 0) { + if (!process.env.SERVICE_ACCOUNT) { + throw new Error("Missing SERVICE_ACCOUNT environment variable"); + } + let config; + try { + config = JSON.parse(process.env.SERVICE_ACCOUNT); + } catch { + throw Error("Invalid SERVICE_ACCOUNT environment variable"); + } + initializeServerApp({ + credential: serverCert(config), }); }