Answer the question
In order to leave comments, you need to log in
How does firebase receive push notifications?
I'm trying to set up push notifications through firebase but it doesn't work.
At the front:
import { initializeApp } from "firebase/app";
import { getMessaging, getToken, onMessage } from "firebase/messaging";
const firebaseConfig = {
apiKey: "xxxxxx,
authDomain: "xxxxx",
databaseURL: 'xxxxx',
projectId: "xxxx",
storageBucket: "xxxxxx",
messagingSenderId: "xxxxx",
appId: "xxxx",
measurementId: "xxxxx"
};
const app = initializeApp(firebaseConfig);
const messaging = getMessaging();
getToken(messaging).then((currentToken) => {
if (currentToken) {
console.log(currentToken)
} else {
console.log('No registration token available. Request permission to generate one.');
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
});
onMessage(messaging, (payload) => {
console.log('Message received. ', payload);
});
User::first()->notify(new PushNotification)
public function routeNotificationForFcm() {
return 'xxxxxx'; // Ключ взял из выхлопа console.log на фронте
}
Answer the question
In order to leave comments, you need to log in
the problem was that I didn't pass vapidKey to getToken() which can be obtained in cloud messagind certificates - they just weren't generated.
But the question through which channel the data comes is still relevant. I don't see any xhr or ws messages when push comes in
And here I don’t quite understand through what channel he should have received them at all?
Add and initialize the FCM SDK
1. If you haven't already, install the Firebase JS SDK and initialize Firebase.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question