laravel-fcm-notification
laravel-fcm-notification copied to clipboard
`401 The request was missing an Authentication Key
The package had been working fine until recently, with noticed on our production server.
full error description below.
Client error: POST https://fcm.googleapis.com/fcm/send
resulted in a 401 The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentication" of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.
response: <HTML> <HEAD> <TITLE>The request was missing an Authentication Key (FCM Token). Please, refer to section "Authentic (truncated...)
+1 :(.
add Bearer before you key
Authorization: Bearer your server key
help
MY SOLUTION -> NODEJS
(async () => {
try {
const body = {
registration_ids: [FCM_TOKEN],
data: {
score: "5x1",
time: "15:10",
},
notification: {
title: "teste",
body: "asf",
subtitle: "asg",
},
};
const http = axios.create({ baseURL: "https://fcm.googleapis.com/fcm" });
const headers = {};
headers["Content-Type"] = "application/json";
headers["Authorization"] = `key=${process.env.AUTH_KEY_GOOGLE}`;
http.defaults.headers.post = headers;
const { data: res } = await http.post("/send", body);
console.log(res);
} catch (error) {
console.log(error);
}
})();