I am getting this error while trying to implement firebase notifications:
Error sending message: Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: Error while making request: incorrect header check. Error code: Z_DATA_ERROR".
at FirebaseAppError.FirebaseError [as constructor] (error.js:44:1)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (error.js:90:1)
at new FirebaseAppError (error.js:125:1)
at firebase-app.js:87:1
I've tried every solution there is online and I'm still getting the error. I tried to synchronize the clock on my machine and it hasn't worked.
Here is my code:
var serviceAccount = require("my path to json file");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "database url"
});
and the function:
notifyme = () => {
const messaging = getMessaging();
const registrationToken = getToken(messaging, {vapidKey: 'my vapid key'})
.then((currentToken) => {
if (currentToken) {
console.log('current token for client: ', currentToken);
const message = {
notification: {
title: 'App name',
body: 'Your room is now available'
},
token: currentToken,
}
admin.messaging().send(message)
.then((response) => {
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
} else {
console.log('No registration token available. Request permission to generate one.');
}
})
.catch((err) => {
console.log('An error occurred while retrieving token. ', err);
});
}
Basically, what i'm trying to do right now is click a button that triggers the notifyme function, and send a notification but I can't get it to work.
I'm running the Ubuntu terminal on my windows pc. I have windows 10 and i'm using npm start for my web app.