Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onLogoutPreviousUserFailed delegate to the IterableAuthDelegate #671

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions swift-sdk/Internal/AuthManager.swift
Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand All @@ -106,6 +106,7 @@ class AuthManager: IterableAuthManagerProtocol {

/// by default, schedule a refresh for 10s
scheduleAuthTokenRefreshTimer(10)
onFailure?(nil)

return
}
Expand Down
6 changes: 4 additions & 2 deletions swift-sdk/Internal/InternalIterableAPI.swift
Expand Up @@ -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
Expand Down Expand Up @@ -546,7 +548,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
if token != nil {
self?.completeUserLogin()
}
})
}, onFailure: nil)
}

private func completeUserLogin() {
Expand Down
4 changes: 3 additions & 1 deletion swift-sdk/Internal/RequestProcessorUtil.swift
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion swift-sdk/IterableAuthManagerProtocol.swift
Expand Up @@ -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()
}
1 change: 1 addition & 0 deletions swift-sdk/IterableConfig.swift
Expand Up @@ -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.
Expand Down