Skip to content

Commit 5c0407d

Browse files
authored
Merge pull request #392 from Iterable/MOB-2154-add-token-to-onsuccess
[MOB-2154] add authToken parameter to onSuccess
2 parents 619a5a9 + 961ba2e commit 5c0407d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

swift-sdk/Internal/AuthManager.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77

88
@objc public protocol IterableInternalAuthManagerProtocol {
99
func getAuthToken() -> String?
10-
func requestNewAuthToken(hasFailedPriorAuth: Bool, onSuccess: (() -> Void)?)
10+
func requestNewAuthToken(hasFailedPriorAuth: Bool, onSuccess: ((String?) -> Void)?)
1111
func logoutUser()
1212
}
1313

@@ -37,7 +37,7 @@ class AuthManager: IterableInternalAuthManagerProtocol {
3737
}
3838

3939
// @objc attribute only needed for the pre-iOS 10 Timer constructor in queueAuthTokenExpirationRefresh
40-
@objc func requestNewAuthToken(hasFailedPriorAuth: Bool = false, onSuccess: (() -> Void)? = nil) {
40+
@objc func requestNewAuthToken(hasFailedPriorAuth: Bool = false, onSuccess: ((String?) -> Void)? = nil) {
4141
guard !self.hasFailedPriorAuth || !hasFailedPriorAuth else {
4242
return
4343
}
@@ -81,13 +81,13 @@ class AuthManager: IterableInternalAuthManagerProtocol {
8181
queueAuthTokenExpirationRefresh(authToken)
8282
}
8383

84-
private func onAuthTokenReceived(retrievedAuthToken: String?, onSuccess: (() -> Void)?) {
84+
private func onAuthTokenReceived(retrievedAuthToken: String?, onSuccess: ((String?) -> Void)?) {
8585
authToken = retrievedAuthToken
8686

8787
storeAuthToken()
8888

8989
if authToken != nil {
90-
onSuccess?()
90+
onSuccess?(authToken)
9191
}
9292

9393
queueAuthTokenExpirationRefresh(self.authToken)

swift-sdk/Internal/IterableAPIInternal.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ final class IterableAPIInternal: NSObject, PushTrackerProtocol, AuthProvider {
121121
_email = email
122122
_userId = nil
123123

124-
authManager.requestNewAuthToken(hasFailedPriorAuth: false) { [weak self] in
124+
authManager.requestNewAuthToken(hasFailedPriorAuth: false) { [weak self] authToken in
125125
self?.loginNewUser()
126126
}
127127

@@ -138,7 +138,7 @@ final class IterableAPIInternal: NSObject, PushTrackerProtocol, AuthProvider {
138138
_email = nil
139139
_userId = userId
140140

141-
authManager.requestNewAuthToken(hasFailedPriorAuth: false) { [weak self] in
141+
authManager.requestNewAuthToken(hasFailedPriorAuth: false) { [weak self] authToken in
142142
self?.loginNewUser()
143143
}
144144

tests/swift-sdk-swift-tests/AuthTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ class AuthTests: XCTestCase {
611611
dateProvider: MockDateProvider())
612612

613613
authManager.requestNewAuthToken(hasFailedPriorAuth: false,
614-
onSuccess: {
615-
XCTAssertEqual(authManager.getAuthToken(), AuthTests.authToken)
614+
onSuccess: { token in
615+
XCTAssertEqual(token, AuthTests.authToken)
616616
condition1.fulfill()
617617
})
618618

0 commit comments

Comments
 (0)