From 48777f20d06533cb47c1dd0d13d3c770fc02ecc8 Mon Sep 17 00:00:00 2001 From: Shepherd Date: Mon, 4 Mar 2024 19:08:32 -0500 Subject: [PATCH] Fix undefined subscription id Fixes the OneSignal-Subscription-Id header being undefined on login from an identified user to another identified user. The pushSubscription model at this point in time is undefined and has no id. Now the subscription id will be passed up from login in the same fashion as identify user. --- src/page/managers/LoginManager.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/page/managers/LoginManager.ts b/src/page/managers/LoginManager.ts index cf4f91c88..6c784ae0b 100644 --- a/src/page/managers/LoginManager.ts +++ b/src/page/managers/LoginManager.ts @@ -185,7 +185,7 @@ export default class LoginManager { if (isIdentified) { // if started off identified, upsert a user - result = await this.upsertUser(userData); + result = await this.upsertUser(userData, subscriptionId); } else { // promoting anonymous user to identified user // from user data, we only use identity (and we remove all aliases except external_id) @@ -196,23 +196,16 @@ export default class LoginManager { static async upsertUser( userData: Partial, + subscriptionId?: string, retry = 5, ): Promise { - logMethodCall('LoginManager.upsertUser', { userData }); + logMethodCall('LoginManager.upsertUser', { userData, subscriptionId }); if (retry === 0) { throw new OneSignalError('Login: upsertUser failed: max retries reached'); } const appId = await MainHelper.getAppId(); - const pushSubscription = - await OneSignal.coreDirector.getPushSubscriptionModel(); - - let subscriptionId; - if (isCompleteSubscriptionObject(pushSubscription?.data)) { - subscriptionId = pushSubscription?.data.id; - } - const userDataCopy = JSON.parse(JSON.stringify(userData)); // only accepts one alias, so remove other aliases only leaving external_id @@ -232,7 +225,7 @@ export default class LoginManager { } else if (status >= 500) { Log.error('Server error. Retrying...'); await awaitableTimeout(RETRY_BACKOFF[retry]); - return this.upsertUser(userDataCopy, retry - 1); + return this.upsertUser(userDataCopy, subscriptionId, retry - 1); } return result;