@@ -344,7 +344,7 @@ extension OSUserExecutor {
344344 OneSignalLog . onesignalLog ( . LL_ERROR, message: " OSUserExecutor no externalId for unauthorized request. " )
345345 return
346346 }
347- OneSignalUserManagerImpl . sharedInstance . invalidateJwtForExternalId ( externalId: externalId, error: nsError)
347+ self . handleUnauthorizedError ( externalId: externalId, error: nsError)
348348 request. sentToClient = false
349349 } else if responseType != . retryable {
350350 // A failed create user request would leave the SDK in a bad state
@@ -360,6 +360,12 @@ extension OSUserExecutor {
360360 }
361361 }
362362 }
363+
364+ func handleUnauthorizedError( externalId: String , error: NSError ) {
365+ if ( jwtConfig. isRequired ?? false ) {
366+ OneSignalUserManagerImpl . sharedInstance. invalidateJwtForExternalId ( externalId: externalId, error: error)
367+ }
368+ }
363369
364370 func fetchIdentityBySubscription( _ user: OSUserInternal ) {
365371 let request = OSRequestFetchIdentityBySubscription ( identityModel: user. identityModel, pushSubscriptionModel: user. pushSubscriptionModel)
@@ -566,6 +572,11 @@ extension OSUserExecutor {
566572 // The subscription has been deleted along with the user, so remove the subscription_id but keep the same push subscription model
567573 OneSignalUserManagerImpl . sharedInstance. pushSubscriptionModel? . subscriptionId = nil
568574 OneSignalUserManagerImpl . sharedInstance. _logout ( )
575+ } else if responseType == . unauthorized && ( self . jwtConfig. isRequired ?? false ) {
576+ if let externalId = request. identityModel. externalId {
577+ self . handleUnauthorizedError ( externalId: externalId, error: nsError)
578+ }
579+ request. sentToClient = false
569580 } else if responseType != . retryable {
570581 // If the error is not retryable, remove from cache and queue
571582 self . removeFromQueue ( request)
0 commit comments