I am trying to make a small nodeJS server deployed on Heroku, saving data to Firestore database. The server is deployed and running correctly. I use Insomnia to test my requests and when I use it locally I can send a post request and save my data object to the database without issues. However, when I try to send a post request to Heroku, I get a 500 error with this message:
{ "code": 16, "details": "Failed to retrieve auth metadata with error: error:0909006C:PEM routines:get_name:no start line", "metadata": {}, "note": "Exception occurred in retry method that was not classified as transient" }
I have read that it is necessary to add real line breaks in the env variable but I guess I am doing it already. This is my initializeApp
function:
admin.initializeApp({
credential: admin.credential.cert({
projectId: process.env.PROJECT_ID,
privateKey: process.env.PRIVATE_KEY
? process.env.PRIVATE_KEY.replace(/\\n/gm, "\n")
: undefined,
clientEmail: process.env.CLIENT_EMAIL
}),
databaseURL: "XXXXX"
});
Any idea how to fix this?
CodePudding user response:
I solved it by copy-pasting the key with break lines directly into Heroku config variables and removing .replace(/\\n/gm, "\n")
from the code.
privateKey: process.env.PRIVATE_KEY
? process.env.PRIVATE_KEY
: undefined