I'm trying to deploy my functions on firebase without needing to add service-account.json
file to my project. This gives me the following error randomly on some functions while deploying:
Error in the build environment
The solution I'm using is given in firebase docs to use
admin.initializeApp(functions.config().firebase);
And if the deploy is successful for all the functions using the above initialization, then it fails when I try to mint a custom token in m y function using admin sdk with following error:
Error: createCustomToken() requires a certificate with "private_key" set.
at FirebaseAuthError.Error (native)
at FirebaseAuthError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseAuthError.PrefixedFirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:85:28)
Is there any problem with using this solution? Or do we need to include the service-account.json file if we need to mint custom token?
I had the same issue and there is a way to bypass having an explicit json file if you have few environment variables.
Initialize it like this :
admin.initializeApp({
credential: admin.credential.cert({
projectId: process.env.FIREBASE_PROJECT_ID,
clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
privateKey: process.env.FIREBASE_PRIVATE_KEY?.replace(/\\n/g, '\n'),
}),
})
the last .replace is required to convert the key to how firebase accepts.
Source of my answer is this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With