fix: logout incorrectly uses the old subscription ID #2327
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
Fixes a bug where the subscription status is lost when a subscription is deleted via the OneSignal dashboard after 'login()' is called.
Details
Motivation
There is a use case where inactive subscriptions are manually removed from the dashboard. If the SDK subsequently calls 'login()' or 'logout()' after such deletion, a new subscription is created, but its status defaults to 'NEVER_SUBSCRIBE' — even though the user had previously subscribed. We expect the newly created subscription to inherit the setup and subscription state of the original.
OTHER - Root Cause Explained
When 'logout()' is called, the SDK sends a 'login-user' request that includes a 'transfer-subscription' operation. Normally, the backend returns a subscription that matches what is stored locally. However, if the original subscription has been deleted from the dashboard, the backend instead returns a newly created default subscription, which lacks prior subscription attributes such as the subscription status.
Scope
The 'TransferSubscription' operation is now only added when an 'externalID' is present.
Testing
Unit testing
Not feasible, as the process involves manual deletion via the dashboard, which cannot be automated in unit tests.
Manual testing
Test Case 1 – 'subscribe()' → 'login()' → delete subscription → 'logout()'
Test Case 2 – 'subscribe()' → 'login()' → 'logout()' → 'login()' (same 'externalID')
Test Case 3 – 'subscribe()' → 'login()' → 'logout()' → 'login()' (different 'externalID')
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is