Skip to content

Commit a4fab3b

Browse files
authored
Merge pull request #608 from Iterable/jay/MOB-5737-token-refresh
[MOB-5737] schedule a default timer of 10s if auth token null
2 parents fe65d8c + b46b528 commit a4fab3b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

swift-sdk/Internal/AuthManager.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,22 @@ class AuthManager: IterableAuthManagerProtocol {
107107
private func queueAuthTokenExpirationRefresh(_ authToken: String?) {
108108
ITBInfo()
109109

110+
clearRefreshTimer()
111+
110112
guard let authToken = authToken, let expirationDate = AuthManager.decodeExpirationDateFromAuthToken(authToken) else {
113+
/// schedule a default timer of 10 seconds if we fall into this case
114+
scheduleAuthTokenRefreshTimer(10)
115+
111116
return
112117
}
113118

114119
let timeIntervalToRefresh = TimeInterval(expirationDate) - dateProvider.currentDate.timeIntervalSince1970 - expirationRefreshPeriod
115120

116-
clearRefreshTimer()
117-
expirationRefreshTimer = Timer.scheduledTimer(withTimeInterval: timeIntervalToRefresh, repeats: false) { [weak self] _ in
121+
scheduleAuthTokenRefreshTimer(timeIntervalToRefresh)
122+
}
123+
124+
private func scheduleAuthTokenRefreshTimer(_ interval: TimeInterval) {
125+
expirationRefreshTimer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { [weak self] _ in
118126
self?.requestNewAuthToken(hasFailedPriorAuth: false)
119127
}
120128
}

0 commit comments

Comments
 (0)