diff --git a/swift-sdk/Internal/AuthManager.swift b/swift-sdk/Internal/AuthManager.swift index 3c9d423ba..aed9ac7b0 100644 --- a/swift-sdk/Internal/AuthManager.swift +++ b/swift-sdk/Internal/AuthManager.swift @@ -35,7 +35,7 @@ class AuthManager: IterableAuthManagerProtocol { hasFailedPriorAuth = false } - func requestNewAuthToken(hasFailedPriorAuth: Bool = false, onSuccess: AuthTokenRetrievalHandler? = nil) { + func requestNewAuthToken(hasFailedPriorAuth: Bool = false, onSuccess: AuthTokenRetrievalHandler? = nil, onFailure: AuthTokenRetrievalHandler? = nil) { ITBInfo() guard !pendingAuth else { @@ -51,7 +51,7 @@ class AuthManager: IterableAuthManagerProtocol { pendingAuth = true delegate?.onAuthTokenRequested { [weak self] retrievedAuthToken in - self?.onAuthTokenReceived(retrievedAuthToken: retrievedAuthToken, onSuccess: onSuccess) + self?.onAuthTokenReceived(retrievedAuthToken: retrievedAuthToken, onSuccess: onSuccess, onFailure: onFailure) } } @@ -96,7 +96,7 @@ class AuthManager: IterableAuthManagerProtocol { queueAuthTokenExpirationRefresh(authToken) } - private func onAuthTokenReceived(retrievedAuthToken: String?, onSuccess: AuthTokenRetrievalHandler? = nil) { + private func onAuthTokenReceived(retrievedAuthToken: String?, onSuccess: AuthTokenRetrievalHandler? = nil, onFailure: AuthTokenRetrievalHandler? = nil) { ITBInfo() pendingAuth = false @@ -106,6 +106,7 @@ class AuthManager: IterableAuthManagerProtocol { /// by default, schedule a refresh for 10s scheduleAuthTokenRefreshTimer(10) + onFailure?(nil) return } diff --git a/swift-sdk/Internal/InternalIterableAPI.swift b/swift-sdk/Internal/InternalIterableAPI.swift index 181db8054..19552e565 100644 --- a/swift-sdk/Internal/InternalIterableAPI.swift +++ b/swift-sdk/Internal/InternalIterableAPI.swift @@ -506,7 +506,9 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { } if config.autoPushRegistration { - disableDeviceForCurrentUser() + disableDeviceForCurrentUser(onFailure: { [weak self] reason, data in + self?.config.authDelegate?.onLogoutPreviousUserFailed(reason) + }) } _email = nil @@ -546,7 +548,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider { if token != nil { self?.completeUserLogin() } - }) + }, onFailure: nil) } private func completeUserLogin() { diff --git a/swift-sdk/Internal/RequestProcessorUtil.swift b/swift-sdk/Internal/RequestProcessorUtil.swift index 797295eaa..e12b49cca 100644 --- a/swift-sdk/Internal/RequestProcessorUtil.swift +++ b/swift-sdk/Internal/RequestProcessorUtil.swift @@ -24,6 +24,8 @@ struct RequestProcessorUtil { }.onError { error in reportFailure(result: result, error: error, failureHandler: onFailure, identifier: identifier) } + } onFailure: { _ in + reportFailure(result: result, error: error, failureHandler: onFailure, identifier: identifier) } } else if error.httpStatusCode == 401, error.iterableCode == JsonValue.Code.badApiKey { ITBError(error.reason) @@ -51,7 +53,7 @@ struct RequestProcessorUtil { }.onError { error in if error.httpStatusCode == 401, error.iterableCode == JsonValue.Code.invalidJwtPayload { ITBError(error.reason) - authManager?.requestNewAuthToken(hasFailedPriorAuth: true, onSuccess: nil) + authManager?.requestNewAuthToken(hasFailedPriorAuth: true, onSuccess: nil, onFailure: nil) } else if error.httpStatusCode == 401, error.iterableCode == JsonValue.Code.badApiKey { ITBError(error.reason) } diff --git a/swift-sdk/IterableAuthManagerProtocol.swift b/swift-sdk/IterableAuthManagerProtocol.swift index 7b3eeb5ba..3f9c08a06 100644 --- a/swift-sdk/IterableAuthManagerProtocol.swift +++ b/swift-sdk/IterableAuthManagerProtocol.swift @@ -7,7 +7,7 @@ import Foundation @objc public protocol IterableAuthManagerProtocol { func getAuthToken() -> String? func resetFailedAuthCount() - func requestNewAuthToken(hasFailedPriorAuth: Bool, onSuccess: ((String?) -> Void)?) + func requestNewAuthToken(hasFailedPriorAuth: Bool, onSuccess: ((String?) -> Void)?, onFailure: ((String?) -> Void)?) func setNewToken(_ newToken: String) func logoutUser() } diff --git a/swift-sdk/IterableConfig.swift b/swift-sdk/IterableConfig.swift index c254db7a9..a4dbdf4b3 100644 --- a/swift-sdk/IterableConfig.swift +++ b/swift-sdk/IterableConfig.swift @@ -56,6 +56,7 @@ import Foundation @objc public protocol IterableAuthDelegate: AnyObject { @objc func onAuthTokenRequested(completion: @escaping AuthTokenRetrievalHandler) @objc func onTokenRegistrationFailed(_ reason: String?) + @objc func onLogoutPreviousUserFailed(_ reason: String?) } /// Iterable Configuration Object. Use this when initializing the API.