pusher / push-notifications-web

Beams Browser notifications
MIT License
39 stars 19 forks source link

Device not found when reloading the page #95

Closed eltonio450 closed 3 years ago

eltonio450 commented 3 years ago

Hello,

We use pusher to push notifications to authenticated users (we don't use device interests)

Sometimes, I guess after a period of inactivity, initialization of the SDK fails with the following error:

{error: "Not found", description: "Device not found"}
description: "Device not found"
error: "Not found"

Here is our code for initialization :

const pusher = () => {
  return new PusherPushNotifications.Client({
    instanceId: __NOTIFICATIONS_INSTANCE_ID__,
  });
};

export const useNotifications = () => {
  const token = useUserToken();
  const usedId = useUserId()

  useEffect(() => {
    (async () => {
      try {
        if (token && userId) {
          const insidePusher = await pusher();

           //fails here I think
          await insidePusher.start();

          //https://pusher.com/docs/beams/reference/web
          await insidePusher.setUserId(userId, {
            fetchToken() {
              return Promise.resolve(
                JSON.parse(token)
              );
            },
          });
        }

        if (!userId) {`
          (await pusher()).stop();
        }
      } catch (err) {
        console.log(err);
      }
    })();
  }, [token]);
};

I think there is an implicit device management by the SDK or Pusher, but somehow, I cannot make it work with web notifications

Thank you

benw-pusher commented 3 years ago

Do you still need support on this issue? To help debug the code and identify the precise cause of failure you could consider adding some logging to your code.

benw-pusher commented 3 years ago

I'll close this out now as I have not received a response. Please reach out to Support at https://support.pusher.com/hc/en-us/requests/new if you need anything more.