question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support setting Firebase private key only at runtime

See original GitHub issue

Describe the bug I’m using a Docker image to deploy my nextjs app however when I run yarn build it seems to expect the private key. This doesn’t make sense for my scenario. The Firebase private key will be supplied at runtime as environment variable so it shouldn’t be needed during yarn build.

See logs:

Step #0: 
Step #0: > Build error occurred
Step #0: FirebaseAppError: Service account object must contain a string "private_key" property.
Step #0:     at FirebaseAppError.FirebaseError [as constructor] (/build/node_modules/firebase-admin/lib/utils/error.js:44:28)
Step #0:     at FirebaseAppError.PrefixedFirebaseError [as constructor] (/build/node_modules/firebase-admin/lib/utils/error.js:90:28)
Step #0:     at new FirebaseAppError (/build/node_modules/firebase-admin/lib/utils/error.js:125:28)
Step #0:     at new ServiceAccount (/build/node_modules/firebase-admin/lib/credential/credential-internal.js:134:19)
Step #0:     at new ServiceAccountCredential (/build/node_modules/firebase-admin/lib/credential/credential-internal.js:68:15)
Step #0:     at Object.exports.cert (/build/node_modules/firebase-admin/lib/credential/credential.js:34:54)
Step #0:     at /build/node_modules/next-firebase-auth/build/index.node.js:2:16259
Step #0:     at init (/build/node_modules/next-firebase-auth/build/index.node.js:2:16290)
Step #0:     at initAuth (/build/.next/server/pages/_app.js:2976:66)
Step #0:     at Module.1TCz (/build/.next/server/pages/_app.js:416:36)
Step #0:     at __webpack_require__ (/build/.next/server/pages/_app.js:23:31)
Step #0:     at Object.0 (/build/.next/server/pages/_app.js:116:18)
Step #0:     at __webpack_require__ (/build/.next/server/pages/_app.js:23:31)
Step #0:     at /build/.next/server/pages/_app.js:91:18
Step #0:     at Object.<anonymous> (/build/.next/server/pages/_app.js:94:10)
Step #0:     at Module._compile (node:internal/modules/cjs/loader:1108:14) {
Step #0:   errorInfo: {
Step #0:     code: 'app/invalid-credential',
Step #0:     message: 'Service account object must contain a string "private_key" property.'
Step #0:   },
Step #0:   codePrefix: 'app'
Step #0: }
Step #0: error Command failed with exit code 1.
Step #0: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Step #0: The command '/bin/sh -c export COOKIE_SECRET_CURRENT=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) &&     export COOKIE_SECRET_PREVIOUS=$COOKIE_SECRET_CURRENT &&     yarn build &&     rm -rf .next/cache' returned a non-zero code: 1

Version Latest, ^0.12.0

Expected result: Ability to run yarn build without having to set the private key

I followed the example application.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
samos123commented, Feb 17, 2021

Spot on. I reread the issue and see how bad a job I did at explaining. I like your 1st approach of only init Firebase admin when you really need it.

1reaction
samos123commented, Feb 25, 2022

confirmed that it’s all working for me now 😄 Glad I was finally able to get off my fork and use the upstream version again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Learn about using and managing API keys for Firebase - Google
An API key is a unique string that's used to route requests to your Firebase project when interacting with Firebase and Google services....
Read more >
Firebase service account private key exposed to admin. ...
If data is only ever available on your backend, then it is "secure" in that only people who have permission to access your...
Read more >
Firebase: Separating configuration from code in Admin SDK
A private key is required to sign data, and currently the Admin SDK can only obtain private keys from service account credentials.
Read more >
Android Keystore system
Generate a new private or secret key · Import encrypted keys into secure hardware · Work with keystore entries · Require user authentication...
Read more >
next-firebase-auth
If your app only uses static pages or doesn't need the Firebase user for ... Then, use the private key in your next-firebase-auth...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found