OneSignal-Website-SDK icon indicating copy to clipboard operation
OneSignal-Website-SDK copied to clipboard

[Bug]: `Onesignal.logout()` error

Open floodfx opened this issue 1 year ago • 0 comments

What happened?

Calling Onesignal.logout() shows error in console.

Error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getIdentityModel')
    at on.<anonymous> (OneSignalSDK.page.es6.js?v=160203:1:220768)
    at Generator.next (<anonymous>)
    at OneSignalSDK.page.es6.js?v=160203:1:267888
    at new Promise (<anonymous>)
    at o (OneSignalSDK.page.es6.js?v=160203:1:267633)
    at on.logout (OneSignalSDK.page.es6.js?v=160203:1:220711)
    at sn.<anonymous> (OneSignalSDK.page.es6.js?v=160203:1:226285)
    at Generator.next (<anonymous>)
    at OneSignalSDK.page.es6.js?v=160203:1:267888
    at new Promise (<anonymous>)

This shows the following line fails: const e = sn.coreDirector.getIdentityModel();

I assume sn.coreDirector is undefined. Tracking this through the code a bit, it appears that coreDirector should be created when OneSignal.init(...) is called. In debugging, I added another init call to ensure it was invoked, and when I did I got an error saying init can only be run once, so I've confirmed init is being called before logout.

What browsers are you seeing the problem on?

Chrome (Chromium)

What operating system are you running?

macOS

Steps to reproduce?

Load in <head>

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

In another section on page:

<script>
  OneSignalDeferred.push(async function(OneSignal) {
    await OneSignal.logout();
  });
</script>


### What did you expect to happen?

No errors and a successful "logout" call.

### Relevant log output

_No response_

floodfx avatar Oct 10 '24 12:10 floodfx