laravel-notification-channels / fcm

Firebase Cloud Messaging (FCM) notifications channel for Laravel
https://laravel-notification-channels.com/
MIT License
472 stars 121 forks source link

Prevent sending to device tokens that no longer exist #163

Closed promatik closed 10 months ago

promatik commented 11 months ago

This is the same as https://github.com/laravel-notification-channels/fcm/issues/91, but I couldn't reopen it.

I'm having the following error;

The message could not be delivered to the device identified by 'eG62o2Kku0O...0sh18PwE5ttj'.

Although the token is syntactically correct, it is not known to the Firebase
project you are using. This could have the following reasons:

- The token has been unregistered from the project. This can happen when a user
  has logged out from the application on the given client, or if they have
  uninstalled or re-installed the application.

- The token has been registered to a different Firebase project than the project
  you are using to send the message. A common reason for this is when you work
  with different application environments and are sending a message from one
  environment to a device in another environment.

So I followed the advice of @rbresjer, and when a NotificationFailed happens, I'm removing the token, nice πŸ‘Œ

The problem is that Notification crashed that request/queue run, anything that goes after that FCM notification will not run, I've already moved everything to before the FcmChannel::class, because in many situations I save the notification to database and also send an email. For instance I wish the mail was the last action, because it takes more time, but I can't do it because if the FCM crashes, it will not send the email.

public function via(User $notifiable): array
{
    return [
        'database',
        'mail',
        FcmChannel::class,
    ];
}

Is there any way to avoid this? To somehow ignore this error? But to keep an Event when to remove the expired token?

Stevemoretz commented 10 months ago

This is the same as #91, but I couldn't reopen it.

I'm having the following error;

The message could not be delivered to the device identified by 'eG62o2Kku0O...0sh18PwE5ttj'.

Although the token is syntactically correct, it is not known to the Firebase
project you are using. This could have the following reasons:

- The token has been unregistered from the project. This can happen when a user
  has logged out from the application on the given client, or if they have
  uninstalled or re-installed the application.

- The token has been registered to a different Firebase project than the project
  you are using to send the message. A common reason for this is when you work
  with different application environments and are sending a message from one
  environment to a device in another environment.

So I followed the advice of @rbresjer, and when a NotificationFailed happens, I'm removing the token, nice πŸ‘Œ

The problem is that Notification crashed that request/queue run, anything that goes after that FCM notification will not run, I've already moved everything to before the FcmChannel::class, because in many situations I save the notification to database and also send an email. For instance I wish the mail was the last action, because it takes more time, but I can't do it because if the FCM crashes, it will not send the email.

public function via(User $notifiable): array
{
    return [
        'database',
        'mail',
        FcmChannel::class,
    ];
}

Is there any way to avoid this? To somehow ignore this error? But to keep an Event when to remove the expired token?

I provided a workaround here: https://github.com/laravel-notification-channels/fcm/issues/167

dwightwatson commented 10 months ago

Thanks for this - please consider using dev-master or looking at #168. We won't throw exceptions on failures now, instead just dispatching events, so the order in which the channel runs shouldn't be an issue.