Skip to content

[Bug]: OneSignal.logout() Not Stopping Targeted Notifications in Ionic Cordova AppΒ #1117

@kunalSBasic

Description

@kunalSBasic

What happened?

Hi team πŸ‘‹,

I'm using Ionic (Angular) with Cordova and implementing login/logout for OneSignal using the new login() and logout() methods.

Below is the exact code I'm using:

logoutUser() {
  let isAndroid = this.platform.is('android');
  let isIOS = this.platform.is('ios');
  let isCordova = this.platform.is('cordova');

  if (isCordova && (isAndroid || isIOS)) {
    console.log('ONESIGNAL LOGOUT', isAndroid, isCordova, isIOS);
    OneSignal.logout();
  }
}

loginUser() {
  let isAndroid = this.platform.is('android');
  let isIOS = this.platform.is('ios');
  let userId = localStorage.getItem('userId');
  let isCordova = this.platform.is('cordova');

  if (isCordova && (isAndroid || isIOS)) {
    console.log('ONESIGNAL LOGIN', isAndroid, isCordova, isIOS);
    OneSignal.login(userId);
  }
}

What works

  • OneSignal.login(userId) works perfectly.

  • External ID is set correctly.

  • Targeted push notifications go to the right user.

The problem

When the user logs out:

  • OneSignal.logout() is called successfully (verified through logs)

  • The device should no longer receive notifications targeted to the previously logged-in external ID

  • But the user still receives targeted notifications meant for the old external ID, even after logout.

Steps to reproduce?

1.Open the Ionic Cordova app on a device.

2.Login using a valid user account β†’ OneSignal.login(userId) is triggered.

3.Send a test push notification targeted to this external ID β†’ device receives it correctly.

4.Logout from the app β†’ OneSignal.logout() is triggered (confirmed in logs).

5.On the OneSignal dashboard, send another push notification targeted to the same user ID.

6.Observed: The device still receives the targeted notification even though the user has logged out.

What did you expect to happen?

After calling OneSignal.logout(), the device should stop receiving notifications targeted to the previous external ID.

Actual behavior

The device continues receiving targeted notifications for the previously logged-in user.

OneSignal Cordova SDK version

5.2.11

Which platform(s) are affected?

  • iOS
  • Android

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions