Using Firebase Admin SDK with Lambda Function

Hey @AnthonyFromTheVault

I came across the same problem and I ended up running the production variable through JSON.parse() to correctly format the key in production.

I continued to use dotenv for local and production env variables, with this ternary condition:

const { FB_PRIVATE_KEY } = process.env
const serviceCredential = {
  // ...
  privateKey: FB_PRIVATE_KEY[0] === '-' ? FB_PRIVATE_KEY : JSON.parse(FB_PRIVATE_KEY),
  // ...
}
2 Likes