Skip to content

Commit 2be9dfa

Browse files
committed
add reason field to auth token fail, move default
1 parent 2c1a275 commit 2be9dfa

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

swift-sdk/Internal/AuthManager.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
import Foundation
66

7+
extension IterableAuthDelegate {
8+
func onTokenRegistrationFailed(_ reason: String? = nil) {
9+
10+
}
11+
}
12+
713
class AuthManager: IterableAuthManagerProtocol {
814
init(delegate: IterableAuthDelegate?,
915
expirationRefreshPeriod: TimeInterval,
@@ -96,7 +102,7 @@ class AuthManager: IterableAuthManagerProtocol {
96102
pendingAuth = false
97103

98104
guard authToken != nil else {
99-
delegate?.onTokenRegistrationFailed()
105+
delegate?.onTokenRegistrationFailed("auth token was nil, scheduling auth token retrieval in 10 seconds")
100106

101107
/// by default, schedule a refresh for 10s
102108
scheduleAuthTokenRefreshTimer(10)
@@ -119,7 +125,7 @@ class AuthManager: IterableAuthManagerProtocol {
119125
clearRefreshTimer()
120126

121127
guard let authToken = authToken, let expirationDate = AuthManager.decodeExpirationDateFromAuthToken(authToken) else {
122-
delegate?.onTokenRegistrationFailed()
128+
delegate?.onTokenRegistrationFailed("auth token was nil or could not decode an expiration date, scheduling auth token retrieval in 10 seconds")
123129

124130
/// schedule a default timer of 10 seconds if we fall into this case
125131
scheduleAuthTokenRefreshTimer(10)

swift-sdk/IterableConfig.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@ import Foundation
5555
/// The delegate for getting the authentication token
5656
@objc public protocol IterableAuthDelegate: AnyObject {
5757
@objc func onAuthTokenRequested(completion: @escaping AuthTokenRetrievalHandler)
58-
@objc func onTokenRegistrationFailed()
59-
}
60-
61-
extension IterableAuthDelegate {
62-
func onTokenRegistrationFailed() {
63-
64-
}
58+
@objc func onTokenRegistrationFailed(_ reason: String?)
6559
}
6660

6761
/// Iterable Configuration Object. Use this when initializing the API.

tests/unit-tests/AuthTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ class AuthTests: XCTestCase {
646646
}
647647
}
648648

649-
func onTokenRegistrationFailed() {
649+
func onTokenRegistrationFailed(_ reason: String?) {
650650

651651
}
652652
}
@@ -678,7 +678,7 @@ class AuthTests: XCTestCase {
678678
completion(AuthTests.authToken)
679679
}
680680

681-
func onTokenRegistrationFailed() {
681+
func onTokenRegistrationFailed(_ reason: String?) {
682682

683683
}
684684
}
@@ -729,7 +729,7 @@ class AuthTests: XCTestCase {
729729
}
730730
}
731731

732-
func onTokenRegistrationFailed() {
732+
func onTokenRegistrationFailed(_ reason: String?) {
733733

734734
}
735735
}
@@ -867,7 +867,7 @@ class AuthTests: XCTestCase {
867867
completion(authTokenGenerator())
868868
}
869869

870-
func onTokenRegistrationFailed() {
870+
func onTokenRegistrationFailed(_ reason: String?) {
871871

872872
}
873873
}

0 commit comments

Comments
 (0)