laravel-web-push-demo
laravel-web-push-demo copied to clipboard
Records in push_subscriptions automatically disappear
Hi there,
Thanks for the awesome library and demo. I have been trying out this in localhost and it works pretty well.
I set up a Artisan command to send notification (to test) like this:
Artisan::command('web-push', function () {
$user = \App\Model\User::find(1);
$user->notify(new \App\Notifications\HelloWorldNotification());
});
After run artisan web-push, the notification appears. But when I click on the notification, it opens the URL (that works as expected), but then the record in push_subscriptions table gets removed automatically.
I dont have any code to remove that at all, and I can 100% reproduce this by:
- click "enable push notification"
- see a new record stored in
push_subscriptionstable - hit
artisan web-push - see new notification(*)
- click on the notification
- it opens localhost(**)
- hit
artisan web-push - now the record in
push_subscriptionsgets removed and no notification is showed
Notes:
- (*): if I dont click the notification, and keep hitting
artisan web-push, I can see new notifications are showing up - (**): after localhost is opened, I checked database and still can see record in
push_subscriptions
My service worker JS is copied from https://github.com/cretueusebiu/laravel-web-push-demo/blob/master/public/sw.js and the demo is copied from https://github.com/cretueusebiu/laravel-web-push-demo/blob/master/resources/js/components/NotificationsDemo.vue, so nothing is changed.
P/S: Not sure if this is relevant, but I console.log('subscription', subscription) in https://github.com/cretueusebiu/laravel-web-push-demo/blob/master/resources/js/components/NotificationsDemo.vue#L74 and it always return null, even after I have enabled the push notification (record is stored in database successfully).
Thanks,
Also found this in logs:
Notification failed to sent for subscription https://fcm.googleapis.com/fcm/send/...: Client error:
POST https://fcm.googleapis.com/fcm/send/...resulted in a410 Goneresponse: push subscription has unsubscribed or expired.