Skip to content

[Bug]: OneSignal External ID not properly cleared on logout/login, causing user association issues #1829

@saucier-consulting

Description

@saucier-consulting

Description:

We're experiencing a critical issue where OneSignal's external ID is not properly cleared when users log out and log back in with different accounts. This causes the new user to be incorrectly associated with the previous user's external ID in the OneSignal dashboard.

Calling OneSignal.login(externalId) after user login does not reliably associate the External ID to the device/user record, especially when switching between users. No errors are reported, but the OneSignal dashboard does not show the External ID for the device.

Sometimes, OneSignal creates new user records when users log out and log back in with different accounts. The new user record is created without an external ID, while the previous user record retains the old external ID but loses its subscription.

Problem Details

Current Behavior:

  • User A logs in → OneSignal external ID is set to User A's ID
  • User A logs out → OneSignal.logout() is called
  • User B logs in → OneSignal external ID still shows User A's ID instead of User B's ID
  • OneSignal dashboard shows User B's subscription but with User A's external ID
  • Notifications may be sent to the wrong user

When a new record is created after logout and re login from different account:

  • User A logs in → OneSignal creates User Record # 1 with External ID = "user-a-id"
  • User A logs out → User Record # 1 retains External ID but loses subscription
  • User B logs in → OneSignal creates User Record # 2 with External ID = empty/null
  • Result: Two user records exist, but only User Record # 2 has an active subscription
Image

Inconsistencies:

  • Two user records for one device
  • New user record has empty external ID
  • Subscription count doesn't match "Subscribed to Push" counter
  • Previous user record retains external ID but loses subscription
Image

Environment Details

  • SDKs & Plugins:
    • react-native-onesignal: 5.2.11
    • onesignal-expo-plugin: 2.0.3
    • Expo: 51.0.39
    • React Native: 0.74.5

Steps to reproduce?

Steps to Reproduce:

Step 1: Login with User A on newly installed app
   OneSignal.login(userA.id);
   OneSignal.User.pushSubscription.optIn();
   
 Check OneSignal Dashboard:
  - User Records: 1 record with External ID = "user-a-id"
  - Subscription Records: 1 active subscription
   
Step 2: Logout User A
   OneSignal.User.pushSubscription.optOut();
   OneSignal.logout();
   
 Check OneSignal Dashboard:
  - User Records: 1 record with External ID = "user-a-id" (no active subscription)
  - Subscription Records: 0 active subscriptions
   
Step 3: Login with User B
   OneSignal.login(userB.id);
   OneSignal.User.pushSubscription.optIn();
   
 Check OneSignal Dashboard:
  - Case 1:
    - After Logging in with user B, OneSignal dashboard still shows user A's External ID
  - Case 2: User Records: 2 records
     * Record 1: External ID = "user-a-id" (no active subscription)
     * Record 2: External ID = empty (has active subscription)
  - Subscription Records: 1 active subscription
  - "Subscribed to Push" shows 0 (inconsistent with subscription count)

What did you expect to happen?

Expected Behavior:

  • User A logs in → OneSignal external ID is set to User A's ID
  • User A logs out → OneSignal external ID is cleared
  • User B logs in → OneSignal external ID is set to User B's ID

OneSignal dashboard shows correct external ID for each user

Additional Info

  • The problem occurs even if login() is called immediately after SDK initialization.
  • The issue affects both Android and iOS devices.

React Native OneSignal SDK version

5.2.13

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