@@ -120,7 +120,7 @@ class OSUserExecutor {
120120 // Translate the last request into a Create User request, if the current user is the same
121121 if let request = transferSubscriptionRequestQueue. last,
122122 let userInstance = OneSignalUserManagerImpl . sharedInstance. _user,
123- OneSignalUserManagerImpl . sharedInstance . isCurrentUser ( request. aliasId) {
123+ userInstance . identityModel . externalId == request. aliasId {
124124 createUser ( userInstance)
125125 }
126126 }
@@ -251,7 +251,7 @@ extension OSUserExecutor {
251251
252252 // If this user already exists and we logged into an external_id, fetch the user data
253253 // Fetch the user only if its the current user and non-anonymous
254- if OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( request. identityModel) ,
254+ if OneSignalUserManagerImpl . sharedInstance. currentUser ( matching : request. identityModel. modelId ) != nil ,
255255 let identity = request. parameters ? [ " identity " ] as? [ String : String ] ,
256256 let onesignalId = request. identityModel. onesignalId,
257257 identity [ OS_EXTERNAL_ID] != nil {
@@ -320,7 +320,7 @@ extension OSUserExecutor {
320320 request. identityModel. hydrate ( identityObject)
321321
322322 // Fetch this user's data if it is the current user
323- guard OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( request. identityModel)
323+ guard OneSignalUserManagerImpl . sharedInstance. currentUser ( matching : request. identityModel. modelId ) != nil
324324 else {
325325 self . executePendingRequests ( )
326326 return
@@ -382,7 +382,7 @@ extension OSUserExecutor {
382382 request. identityModelToUpdate. hydrate ( aliases)
383383
384384 // the anonymous user has been identified, still need to Fetch User as we cleared local data
385- if OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( request. identityModelToUpdate) {
385+ if OneSignalUserManagerImpl . sharedInstance. currentUser ( matching : request. identityModelToUpdate. modelId ) != nil {
386386 // Add onesignal ID to new records because an immediate fetch may not return the newly-applied external ID
387387 self . newRecordsState. add ( onesignalId, true )
388388 self . fetchUser ( aliasLabel: OS_ONESIGNAL_ID, aliasId: onesignalId, identityModel: request. identityModelToUpdate)
@@ -397,8 +397,7 @@ extension OSUserExecutor {
397397
398398 self . removeFromQueue ( request)
399399
400- if let userInstance = OneSignalUserManagerImpl . sharedInstance. _user,
401- OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( request. identityModelToUpdate) {
400+ if let userInstance = OneSignalUserManagerImpl . sharedInstance. currentUser ( matching: request. identityModelToUpdate. modelId) {
402401 // Generate a Create User request, if it's still the current user
403402 self . createUser ( userInstance)
404403 } else {
@@ -412,8 +411,8 @@ extension OSUserExecutor {
412411 } else if responseType == . missing {
413412 self . removeFromQueue ( request)
414413 self . executePendingRequests ( )
415- // Logout if the user in the SDK is the same
416- guard OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( request. identityModelToUpdate)
414+ // Logout only if this request's user is still current, so a concurrent login can't log out the wrong user.
415+ guard OneSignalUserManagerImpl . sharedInstance. currentUser ( matching : request. identityModelToUpdate. modelId ) != nil
417416 else {
418417 return
419418 }
@@ -448,15 +447,12 @@ extension OSUserExecutor {
448447 OneSignalCoreImpl . sharedClient ( ) . execute ( request) { response in
449448 self . removeFromQueue ( request)
450449
451- // A fetch for a user that is no longer current is stale
452- guard OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( request. identityModel) else {
453- self . executePendingRequests ( )
454- return
455- }
456-
457- if let response = response {
450+ // A fetch for a user that is no longer current is stale. A login can land while this
451+ // response is in flight, so the clear must apply to the user the response is for.
452+ if let user = OneSignalUserManagerImpl . sharedInstance. currentUser ( matching: request. identityModel. modelId) ,
453+ let response = response {
458454 // Clear local data in preparation for hydration
459- OneSignalUserManagerImpl . sharedInstance. clearUserData ( )
455+ OneSignalUserManagerImpl . sharedInstance. clearUserData ( user )
460456 self . parseFetchUserResponse ( response: response, identityModel: request. identityModel, originalPushToken: OneSignalUserManagerImpl . sharedInstance. pushSubscriptionImpl. token)
461457
462458 // If this is a on-new-session's fetch user call, check that the subscription still exists
@@ -485,8 +481,8 @@ extension OSUserExecutor {
485481 let responseType = OSNetworkingUtils . getResponseStatusType ( error. code)
486482 if responseType == . missing {
487483 self . removeFromQueue ( request)
488- // Logout if the user in the SDK is the same
489- guard OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( request. identityModel)
484+ // Logout only if this request's user is still current, so a concurrent login can't log out the wrong user.
485+ guard OneSignalUserManagerImpl . sharedInstance. currentUser ( matching : request. identityModel. modelId ) != nil
490486 else {
491487 return
492488 }
@@ -541,14 +537,14 @@ extension OSUserExecutor {
541537 }
542538 }
543539
544- // Check if the current user is the same as the one in the request
540+ // Hydrate onto the user this response is for
545541 // If user has changed, don't hydrate, except for push subscription above
546- guard OneSignalUserManagerImpl . sharedInstance. isCurrentUser ( identityModel) else {
542+ guard let user = OneSignalUserManagerImpl . sharedInstance. currentUser ( matching : identityModel. modelId ) else {
547543 return
548544 }
549545
550546 if let propertiesObject = parsePropertiesObjectResponse ( response) {
551- OneSignalUserManagerImpl . sharedInstance . _user ? . propertiesModel. hydrate ( propertiesObject)
547+ user . propertiesModel. hydrate ( propertiesObject)
552548 }
553549
554550 // Now parse email and sms subscriptions
0 commit comments