Skip to content

Commit

Permalink
Changing Type in Session Init just to avoid inside conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
LetoFranco committed Feb 23, 2022
1 parent dccf2e9 commit f07c246
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions ios-base/Common/Models/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ struct Session: Codable {
var accessToken: String?
var expiry: Date?

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

private enum CodingKeys: String, CodingKey {
case uid
Expand All @@ -33,18 +35,15 @@ struct Session: Codable {
self.expiry = expires
}

init?(headers: [String: Any]) {
var loweredHeaders = headers
loweredHeaders.lowercaseKeys()
guard let stringHeaders = loweredHeaders as? [String: String] else {
return nil
}
if let expiryString = stringHeaders[APIClient.HTTPHeader.expiry.rawValue],
init?(headers: [String: String]) {
var loweredKeysHeaders = headers
loweredKeysHeaders.lowercaseKeys()
if let expiryString = loweredKeysHeaders[APIClient.HTTPHeader.expiry.rawValue],
let expiryNumber = Double(expiryString) {
expiry = Date(timeIntervalSince1970: expiryNumber)
}
uid = stringHeaders[APIClient.HTTPHeader.uid.rawValue]
client = stringHeaders[APIClient.HTTPHeader.client.rawValue]
accessToken = stringHeaders[APIClient.HTTPHeader.token.rawValue]
uid = loweredKeysHeaders[APIClient.HTTPHeader.uid.rawValue]
client = loweredKeysHeaders[APIClient.HTTPHeader.client.rawValue]
accessToken = loweredKeysHeaders[APIClient.HTTPHeader.token.rawValue]
}
}
2 changes: 1 addition & 1 deletion ios-base/Networking/Services/AuthenticationServices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class AuthenticationServices {
UserDataManager.currentUser = User(
dictionary: response["user"] as? [String: Any] ?? [:]
)
if let headers = headers as? [String: Any] {
if let headers = headers as? [String: String] {
SessionManager.currentSession = Session(headers: headers)
}
}
Expand Down

0 comments on commit f07c246

Please sign in to comment.