From 76d018a0c1e303ba29c556578555d71e95d040da Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Thu, 19 Sep 2024 22:54:24 +0000 Subject: [PATCH] fix logout() when push sub doesn't exists 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. --- src/page/managers/LoginManager.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/page/managers/LoginManager.ts b/src/page/managers/LoginManager.ts index 6c784ae0b..c40443f75 100644 --- a/src/page/managers/LoginManager.ts +++ b/src/page/managers/LoginManager.ts @@ -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, false, ); + // Initialize as non-local, make a request to OneSignal to create a new anonymous user await UserDirector.initializeUser(false); }