pusher / push-notifications-web

Beams Browser notifications
MIT License
39 stars 19 forks source link

Client SDK to request a Beams Token from your backend server #97

Open ddhanak opened 3 years ago

ddhanak commented 3 years ago

Allow passing in the beams token when setting userId (instead of fetching from tokenProvider).

https://github.com/pusher/push-notifications-web/blob/master/src/push-notifications.js#L328

Use case: we have implemented our own logic to fetch the beams token (and we do not want to use the TokenProvider class that sends a request for us through the SDK).

ddhanak commented 3 years ago

@benw-pusher hi ben, is it possible to know if this will be prioritized or not?

benw-pusher commented 3 years ago

I have shared the feedback internally but at this time we cannot commit to a release.

ddhanak commented 1 year ago

@benw-pusher hi any news on this? it has been more than a year now.

benw-pusher commented 1 year ago

Unfortunately, at this time we don't have this work scheduled.

daniel-shuy commented 1 year ago

Actually, this is already possible.

Client.setUserId() takes in an interface (ITokenProvider): https://github.com/pusher/push-notifications-web/blob/691ee3200e781a5313b4be331a7b2aa3aac665db/index.d.ts#L42 https://github.com/pusher/push-notifications-web/blob/691ee3200e781a5313b4be331a7b2aa3aac665db/index.d.ts#L4-L6 https://github.com/pusher/push-notifications-web/blob/691ee3200e781a5313b4be331a7b2aa3aac665db/index.d.ts#L1-L3

You'll just need to create your own ITokenProvider implementation that returns the token immediately, e.g.

client.setUserId(userId, {
  fetchToken: () => Promise.resolve({ token }),
});
lukepearce commented 6 months ago

I have tried multiple versions of the custom ITokenProvider approach, and it's working locally (I can see "Device paired with User" in the Pusher debug console) but when it's deployed to prod, I get Error: Unexpected status code 401: Unauthorized, Invalid JWT signature.

The token is being returned by my server and when decoded, it is the same shape as it is locally.

Any idea what might be happening?