Closed momostafa closed 4 months ago
I managed to fix above error but no notifications received at all and i am getting below error at google developer tools
Violation] Only request notification permission in response to a user gesture.
token-manager.ts:167 Uncaught (in promise) DOMException: Failed to execute 'subscribe' on 'PushManager': The provided applicationServerKey is not valid.
at getPushSubscription (https://www.gstatic.com/firebasejs/10.12.2/firebase-messaging.js:1:20047)
at async getTokenInternal (https://www.gstatic.com/firebasejs/10.12.2/firebase-messaging.js:1:19920)
at async https://bulksms.test/admin/user-notifications:7101:29
Appreciate your response on this issues thanks
firebase-messaging-sw.js
// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here. Other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js');
try
{
// Initialize the Firebase app in the service worker by passing in
// your app's Firebase config object.
// https://firebase.google.com/docs/web/setup#config-object
firebase.initializeApp({
apiKey: "{{ apiKey }}",
authDomain: "{{ authDomain }}",
databaseURL: "{{ databaseURL }}",
projectId: "{{ projectId }}",
storageBucket: "{{ storageBucket }}",
messagingSenderId: "{{ messagingSenderId }}",
appId: "{{ appId }}",
measurementId: "{{ measurementId }}"
});
// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();
messaging.onBackgroundMessage((payload) => {
//
{{ sound }}
let options = {
body: "",
icon: "",
image: "",
tag: "alert",
};
if(payload.data.body){
options.body = payload.data.body;
}
if(payload.data.image){
options.icon = payload.data.image;
}
let notification = self.registration.showNotification(
payload.data.title,
options
);
if(payload.data.url){
// link to page on clicking the notification
notification.onclick = (payload) => {
window.open(payload.data.url);
};
}
});
}
catch(e) {
console.log(e)
}
@momostafa it's easy, your user don't have a token, that's a problem that mean you need to add
use InteractsWithFCM;
to your user model
@momostafa it's easy, your user don't have a token, that's a problem that mean you need to add
use InteractsWithFCM;
to your user model
I already had this in place, I have removed your plugin and implemented my own. Thanks for your reply
Hi,
I am getting below error when trying to send using FCM
No registration tokens provided in /vendor/kreait/firebase-php/src/Firebase/Messaging/RegistrationTokens.php:61