Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logout() when push subscription doesn't exists #1194

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Sep 19, 2024

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:

  1. OneSignal.login("A");
  2. OneSignal.User.addEmail("[email protected]");
  3. OneSignal.logout();
  4. OneSignal.User.addEmail("[email protected]");
  5. Observe [email protected] was added to the correct User.

Info

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • 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:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • 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

Related Tickets



This change is Reviewable

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.
Copy link
Contributor

@shepherd-l shepherd-l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Tested on Chrome Version 128.0.6613.138 on macOS Sonoma 14.6.1 with the web example app

Steps:

  1. Clear web cache
  2. Open example web app and do not accept the push notification permission (inorder to not create a push sub)
  3. OneSignal.login("TestUser");
  4. OneSignal.logout();

This PR does not produce an error
Reproduced error on main:

Dev-OneSignalSDK.page.es6.js?v=160202:2072 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'modelId')  
    at OSModelStore.subscribeUpdateListener (Dev-OneSignalSDK.page.es6.js?v=160202:2072:41)  
    at OSModelStore.add (Dev-OneSignalSDK.page.es6.js?v=160202:2056:14)  
    at CoreModuleDirector.add (Dev-OneSignalSDK.page.es6.js?v=160202:915:32)  
    at LoginManager.<anonymous> (Dev-OneSignalSDK.page.es6.js?v=160202:6476:87)  
    at Generator.next (<anonymous>)  
    at fulfilled (Dev-OneSignalSDK.page.es6.js?v=160202:18277:58)

Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @emawby and @rgomezp)

@jkasten2 jkasten2 merged commit 24895d0 into main Sep 20, 2024
4 of 5 checks passed
@jkasten2 jkasten2 deleted the fix/logout_without_push_sub_2024-09-19 branch September 20, 2024 17:06
@shepherd-l shepherd-l mentioned this pull request Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants