Skip to content

Commit

Permalink
fix logout() when push sub doesn't exists
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jkasten2 committed Sep 19, 2024
1 parent 1f64c20 commit 76d018a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/page/managers/LoginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,20 @@ export default class LoginManager {
const pushSubModel =
await OneSignal.coreDirector.getPushSubscriptionModel();
await OneSignal.coreDirector.resetModelRepoAndCache();

// Initialize as a local User, as we don't have a push subscription to create a remote anonymous user.
if (pushSubModel === undefined) {
await UserDirector.initializeUser(true);
return;
}

// add the push subscription model back to the repo since we need at least 1 sub to create a new user
OneSignal.coreDirector.add(
ModelName.PushSubscriptions,
pushSubModel as OSModel<SupportedModel>,
false,
);
// Initialize as non-local, make a request to OneSignal to create a new anonymous user
await UserDirector.initializeUser(false);
}

Expand Down

0 comments on commit 76d018a

Please sign in to comment.