Skip to content

Commit e49f910

Browse files
committed
Changing Type in Session Init just to avoid inside conversion
1 parent 6b1ca16 commit e49f910

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

ios-base/Common/Models/Session.swift

+10-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ struct Session: Codable {
1515
var accessToken: String?
1616
var expiry: Date?
1717

18-
var isValid: Bool { [uid, accessToken, client].allSatisfy { $0 != nil } }
18+
var isValid: Bool {
19+
[uid, accessToken, client].allSatisfy { !($0 ?? "").isEmpty }
20+
}
1921

2022
private enum CodingKeys: String, CodingKey {
2123
case uid
@@ -34,19 +36,15 @@ struct Session: Codable {
3436
self.expiry = expires
3537
}
3638

37-
init?(headers: [AnyHashable: Any]) {
38-
guard var stringHeaders = headers as? [String: String] else {
39-
return nil
40-
}
41-
42-
stringHeaders.lowercaseKeys()
43-
44-
if let expiryString = stringHeaders[HTTPHeader.expiry.rawValue],
39+
init?(headers: [String: String]) {
40+
var loweredKeysHeaders = headers
41+
loweredKeysHeaders.lowercaseKeys()
42+
if let expiryString = loweredKeysHeaders[APIClient.HTTPHeader.expiry.rawValue],
4543
let expiryNumber = Double(expiryString) {
4644
expiry = Date(timeIntervalSince1970: expiryNumber)
4745
}
48-
uid = stringHeaders[HTTPHeader.uid.rawValue]
49-
client = stringHeaders[HTTPHeader.client.rawValue]
50-
accessToken = stringHeaders[HTTPHeader.token.rawValue]
46+
uid = loweredKeysHeaders[APIClient.HTTPHeader.uid.rawValue]
47+
client = loweredKeysHeaders[APIClient.HTTPHeader.client.rawValue]
48+
accessToken = loweredKeysHeaders[APIClient.HTTPHeader.token.rawValue]
5149
}
5250
}

ios-base/Networking/Services/AuthenticationServices.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ internal class AuthenticationServices {
167167
private func saveUserSession(
168168
_ user: User?,
169169
headers: [AnyHashable: Any]
170-
) -> Bool {
171-
UserDataManager.currentUser = user
172-
sessionManager.currentSession = Session(headers: headers)
173-
174-
return UserDataManager.currentUser != nil && sessionManager.isSessionValid
170+
) {
171+
UserDataManager.currentUser = User(
172+
dictionary: response["user"] as? [String: Any] ?? [:]
173+
)
174+
if let headers = headers as? [String: String] {
175+
SessionManager.currentSession = Session(headers: headers)
176+
}
175177
}
176178
}

0 commit comments

Comments
 (0)