Skip to content

Commit 01fde6f

Browse files
committed
Don't send push sub for previous users to avoid transfer
* Remove the push subscription if not current user; we don't want to transfer the push sub. * This detail is meant to handle JWT on, and previous failed user creates can be sent even though the user has changed successfully. * However, don't remove the push sub if the user is anonymous or else the create will fail. Also, when JWT is off and anonymous users can be created, this will block requests until it succeeds so there is no risk of accidentally transferring the push sub to an old user.
1 parent 5433ebb commit 01fde6f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

iOS_SDK/OneSignalSDK/OneSignalUser/Source/Executors/OSUserExecutor.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,20 @@ extension OSUserExecutor {
342342
return
343343
}
344344

345-
// Hook up push subscription model if exists, it may be updated with a subscription_id, etc.
346-
if let modelId = request.pushSubscriptionModel?.modelId,
347-
let pushSubscriptionModel = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModelStore.getModel(modelId: modelId) {
348-
request.pushSubscriptionModel = pushSubscriptionModel
349-
request.updatePushSubscriptionModel(pushSubscriptionModel)
345+
if OneSignalUserManagerImpl.sharedInstance.isCurrentUser(request.identityModel) {
346+
// Hook up push subscription model if exists, it may be updated with a subscription_id, etc.
347+
if let modelId = request.pushSubscriptionModel?.modelId,
348+
let pushSubscriptionModel = OneSignalUserManagerImpl.sharedInstance.pushSubscriptionModelStore.getModel(modelId: modelId) {
349+
request.pushSubscriptionModel = pushSubscriptionModel
350+
request.updatePushSubscriptionModel(pushSubscriptionModel)
351+
}
352+
} else if request.identityModel.externalId != nil {
353+
/*
354+
Remove the push subscription if not current user; we don't want to transfer the push sub.
355+
However, don't remove if the user is anonymous or else the create will fail.
356+
This detail is meant to handle JWT on, and previous failed user creates can be sent even though the user has changed.
357+
*/
358+
request.parameters?.removeValue(forKey: "subscriptions")
350359
}
351360

352361
guard request.addJWTHeaderIsValid(identityModel: request.identityModel) else {

0 commit comments

Comments
 (0)