@@ -15,7 +15,9 @@ struct Session: Codable {
15
15
var accessToken : String ?
16
16
var expiry : Date ?
17
17
18
- var isValid : Bool { [ uid, accessToken, client] . allSatisfy { $0 != nil } }
18
+ var isValid : Bool {
19
+ [ uid, accessToken, client] . allSatisfy { !( $0 ?? " " ) . isEmpty }
20
+ }
19
21
20
22
private enum CodingKeys : String , CodingKey {
21
23
case uid
@@ -34,19 +36,15 @@ struct Session: Codable {
34
36
self . expiry = expires
35
37
}
36
38
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] ,
45
43
let expiryNumber = Double ( expiryString) {
46
44
expiry = Date ( timeIntervalSince1970: expiryNumber)
47
45
}
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]
51
49
}
52
50
}
0 commit comments