Escaping issue with firebase privateKey as a Heroku config variable

后端 未结 3 1593
南笙
南笙 2020-12-13 14:03

I\'m trying to create an Heroku node task that reads data from Firebase and console.log it.

My node script (located inside the /bin directory) is:

re         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 14:21

    I had the same problem today. You need to sanitize the read private key by replacing \\n characters with \n.

    admin.initializeApp({
      credential: admin.credential.cert({
        "projectId": process.env.FIREBASE_PROJECT_ID,
        "private_key": process.env.FIREBASE_PRIVATE_KEY.replace(/\\n/g, '\n'),
        "clientEmail": process.env.FIREBASE_CLIENT_EMAIL,
      }),
      databaseURL: process.env.FIREBASE_DATABASE_URL,
    });
    

提交回复
热议问题