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;