laravel-notification-channels / webpush

Webpush notifications channel for Laravel.
http://laravel-notification-channels.com
MIT License
681 stars 119 forks source link

Got ErrorException with message 'Subscription should have a content encoding' #163

Open yoviprasetyo opened 3 years ago

yoviprasetyo commented 3 years ago

Hi,

I develop Laravel App with your packages.

This is my route

Route::post('/save-subscription', 'NotificationController@subscribe')->name('subscription.save');

That route is to save the JSON I just save the endpoint and don't care for the rest. I use $user->updatePushSubscription($request->endpoint); to save it. Saved to DB.

But, when I try to notify the User, I got this error.

ErrorException with message 'Subscription should have a content encoding'

I ever see your code that the available value is aesgcm and aes128gcm. But it only return null and no notification occured.

How to solve this error?

imrodrigoalves commented 2 years ago

Hey,

Have been facing the same issue? Any luck?

imrodrigoalves commented 2 years ago

Okay, small update.

There's a bug that will not apply the default value "aesgcm" if not provided.

To by-pass this you can:

  1. Implement your own version of the Subscription class that applies the value correctly
  2. Send always the value "aesgcm" when updating the subscription
auth('api')->user()->updatePushSubscription($sub['endpoint'], null, null, "aesgcm");

I don't think this looks good unless you're on PHP 8.x and can make use of named parameters.