This error message based on its frequent appearance in SO seems to be a general response to a number of errors. I am trying to do a FCM sendAll(...) from a Nestjs microservice backend. I initalized the firebase in main.ts like so:
.......
......
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
AppModule,
{
transport: Transport.TCP,
options,
}
);
const configService: ConfigService = app.get(ConfigService);
const adminConfig: ServiceAccount = {
"projectId": configService.get<string>('FIREBASE_PROJECT_ID'),
"privateKey": configService.get<string>('FIREBASE_PRIVATE_KEY')
.replace(/\\n/g, '\n'),
"clientEmail": configService.get<string>('FIREBASE_CLIENT_EMAIL'),
};
firebase.initializeApp({
credential: firebase.credential.cert(adminConfig),
});
await app.listen();
}
bootstrap();
My .ENV is like so:
FIREBASE_PRIVATE_KEY = "-----BEGIN PRIVATE KEY-----\nMI...\n-----END PRIVATE KEY-----\n",
FIREBASE_CLIENT_EMAIL = 'abc@my.com',
FIREBASE_PROJECT_ID = 'xxx-genysis'
apparently firebase was initialized and the credentials were ok. I do get an error if I substitute invalid credentials.
However, when I tried to execute the sendAll(...) in my notification.service.ts like so:
import * as firebase from 'firebase-admin';
......
.....
async sendNotifications(data) {
const messages = await this.getMessages(data.tokens,data.message,data.title);
const promises = [];
for (let i = 0; i + 10 <= messages.length; i += 10) {
const batch = messages.slice(i, i + 10);
promises.push(firebase.messaging().sendAll(batch));
}
await Promise.all(promises);
}
I am getting the following error:
error:0909006C:PEM routines:get_name:no start line
Error: error:0909006C:PEM routines:get_name:no start line
at Sign.sign (node:internal/crypto/sig:131:29)
at Object.sign (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/jsonwebtoken/node_modules/jwa/index.js:152:45)
at Object.jwsSign [as sign] (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/jsonwebtoken/node_modules/jws/lib/sign-stream.js:32:24)
at Object.module.exports [as sign] (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/jsonwebtoken/sign.js:204:16)
at ServiceAccountCredential.createAuthJwt_ (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/firebase-admin/lib/app/credential-internal.js:105:20)
at ServiceAccountCredential.getAccessToken (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/firebase-admin/lib/app/credential-internal.js:77:28)
at FirebaseAppInternals.refreshToken (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/firebase-admin/lib/app/firebase-app.js:45:49)
at FirebaseAppInternals.getToken (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/firebase-admin/lib/app/firebase-app.js:37:25)
at AuthorizedHttpClient.getToken (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/firebase-admin/lib/utils/api-request.js:612:34)
at AuthorizedHttpClient.send (/Applications/GenysisBuild/GenysisNest/genysis-notifications/node_modules/firebase-admin/lib/utils/api-request.js:600:21)
based on the responses to the error messages it would appears I have a bad private_key but this can't be the case since the same private key was used to initialize firebase. Can anyone shed some light on what's going on here?
EDIT: A try/catch error around the sendAll() result in the following error:
{"library":"PEM routines","function":"get_name","reason":"no start line","code":"ERR_OSSL_PEM_NO_START_LINE"}