OneSignal is a push notification service for web and mobile apps. This SDK makes it easy to integrate your website with OneSignal Push Notifications. https://onesignal.com
Other
389
stars
115
forks
source link
Fix logout() when push subscription doesn't exists #1194
Fix OneSignal.logout() so it doesn't throw an error if there isn't a push subscription.
Details
A push subscription only exists if the end-user accepted notifications at some point. OneSignal.logout() made this bad assumption it always existed.
The fix is to check this and create a local only user instead of making a call to OneSignal if there isn't a push subscription.
Validation
Tests
Tested on Chrome Version 128.0.6613.138 on Windows 11 23H2
Scenarios:
OneSignal.login("A");
OneSignal.User.addEmail("a@a.com");
OneSignal.logout();
OneSignal.User.addEmail("b@b.com");
Observe b@b.com was added to the correct User.
Info
Checklist
[x] All the automated tests pass or I explained why that is not possible
[X] I have personally tested this on my machine or explained why that is not possible
[X] I have included test coverage for these changes or explained why they are not needed
No current login / logout tests, there is another project to add test coverage to this flow.
Programming Checklist
Interfaces:
[X] Don't use default export
[X] New interfaces are in model files
Functions:
[X] Don't use default export
[X] All function signatures have return types
[X] Helpers should not access any data but rather be given the data to operate on.
Typescript:
[X] No Typescript warnings
[X] Avoid silencing null/undefined warnings with the exclamation point
Other:
[X] Iteration: refrain from using elem of array syntax. Prefer forEach or use map
[X] Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context
Description
One-Line Summary
Fix OneSignal.logout() so it doesn't throw an error if there isn't a push subscription.
Details
A push subscription only exists if the end-user accepted notifications at some point.
OneSignal.logout()
made this bad assumption it always existed.The fix is to check this and create a local only user instead of making a call to OneSignal if there isn't a push subscription.
Validation
Tests
Tested on Chrome Version 128.0.6613.138 on Windows 11 23H2 Scenarios:
Info
Checklist
Programming Checklist Interfaces:
Functions:
Typescript:
Other:
elem of array
syntax. PreferforEach
or usemap
context
if possible. Instead, we can pass it to function/constructor so that we don't callOneSignal.context
Related Tickets
This change is