OneSignal/OneSignal-Website-SDK

[Question]: Whats wrong with the code web client's player IDs ? SOLVED

Closed this issue · 0 comments

Vitaee commented

How can we help?

I have below code for my django web project. I serve worker js with nginx there is no any issue.
The below code block was working fine until yesterday. But now i don't know what happened its just stopped working.

Still i can see the notification prompt for the subscription but even giving all permissions from browser, no one was registered in to onesignal.

So i can't send any notification to my clients. I have growth plan on onesignal.

<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
  <script>
    window.OneSignalDeferred = window.OneSignalDeferred || [];
    OneSignalDeferred.push(function(OneSignal) {
      OneSignal.init({
        appId: "my-best-app-id",
      });

      OneSignal.User.PushSubscription.addEventListener("change", pushSubscriptionChangeListener);


    });

    function pushSubscriptionChangeListener(event) {
        console.log("pushSubscriptionChangeListener triggered!")
        console.log(event)
        console.log("^^^^^^^^EVENT PRINTED^^^^^^^^")
        
        if (event.current.token) {
          console.log(`The push subscription has received a token!`);
          console.log(event.current)

          const url = 'https://www.bestwebsite.com/store-onesignal-id/';
          var userToken = `{{ token }}`

          const data = { onesignal_id: event.current.id };

              fetch(url, {
                method: 'POST',
                headers: {
                  'Content-Type': 'application/json',
                  'Authorization': `token ${userToken}`
                },
                body: JSON.stringify(data),
              });
          }
       }
  </script>

please see the below screenshot:

ss

for debug purposes i simple print the event object and i got null objects. These objects are weren't null.

Why everything is null ? and Whats wrong with my code? or how can i get player ID on web is there any other way?