Skip to content

Commit

Permalink
style: swift format
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Apr 1, 2024
1 parent ad0db38 commit 69e1389
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
4 changes: 3 additions & 1 deletion Sources/Auth/Internal/SessionStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ struct StoredSession: Codable {

init(session: Session, expirationDate: Date? = nil) {
self.session = session
self.expirationDate = expirationDate ?? Date().addingTimeInterval(session.expiresIn)
self.expirationDate = expirationDate
?? session.expiresAt.map(Date.init(timeIntervalSince1970:))
?? Date().addingTimeInterval(session.expiresIn)
}
}

Expand Down
50 changes: 25 additions & 25 deletions Sources/Auth/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
self.lastSignInAt = lastSignInAt
self.updatedAt = updatedAt
}
enum CodingKeys: CodingKey {

private enum CodingKeys: CodingKey {
case id
case identityId
case userId
Expand All @@ -231,32 +231,32 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable {
case lastSignInAt
case updatedAt
}

public init(from decoder: any Decoder) throws {
let container: KeyedDecodingContainer<UserIdentity.CodingKeys> = try decoder.container(keyedBy: UserIdentity.CodingKeys.self)
self.id = try container.decode(String.self, forKey: UserIdentity.CodingKeys.id)
self.identityId = try container.decodeIfPresent(UUID.self, forKey: UserIdentity.CodingKeys.identityId) ?? UUID(uuid: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))
self.userId = try container.decode(UUID.self, forKey: UserIdentity.CodingKeys.userId)
self.identityData = try container.decodeIfPresent([String : AnyJSON].self, forKey: UserIdentity.CodingKeys.identityData)
self.provider = try container.decode(String.self, forKey: UserIdentity.CodingKeys.provider)
self.createdAt = try container.decode(Date.self, forKey: UserIdentity.CodingKeys.createdAt)
self.lastSignInAt = try container.decode(Date.self, forKey: UserIdentity.CodingKeys.lastSignInAt)
self.updatedAt = try container.decode(Date.self, forKey: UserIdentity.CodingKeys.updatedAt)

let container = try decoder.container(keyedBy: CodingKeys.self)

id = try container.decode(String.self, forKey: .id)
identityId = try container.decodeIfPresent(UUID.self, forKey: .identityId)
?? UUID(uuidString: "00000000-0000-0000-0000-000000000000")!
userId = try container.decode(UUID.self, forKey: .userId)
identityData = try container.decodeIfPresent([String: AnyJSON].self, forKey: .identityData)
provider = try container.decode(String.self, forKey: .provider)
createdAt = try container.decode(Date.self, forKey: .createdAt)
lastSignInAt = try container.decode(Date.self, forKey: .lastSignInAt)
updatedAt = try container.decode(Date.self, forKey: .updatedAt)
}

public func encode(to encoder: any Encoder) throws {
var container: KeyedEncodingContainer<UserIdentity.CodingKeys> = encoder.container(keyedBy: UserIdentity.CodingKeys.self)
try container.encode(self.id, forKey: UserIdentity.CodingKeys.id)
try container.encode(self.identityId, forKey: UserIdentity.CodingKeys.identityId)
try container.encode(self.userId, forKey: UserIdentity.CodingKeys.userId)
try container.encodeIfPresent(self.identityData, forKey: UserIdentity.CodingKeys.identityData)
try container.encode(self.provider, forKey: UserIdentity.CodingKeys.provider)
try container.encode(self.createdAt, forKey: UserIdentity.CodingKeys.createdAt)
try container.encode(self.lastSignInAt, forKey: UserIdentity.CodingKeys.lastSignInAt)
try container.encode(self.updatedAt, forKey: UserIdentity.CodingKeys.updatedAt)
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(id, forKey: .id)
try container.encode(identityId, forKey: .identityId)
try container.encode(userId, forKey: .userId)
try container.encodeIfPresent(identityData, forKey: .identityData)
try container.encode(provider, forKey: .provider)
try container.encode(createdAt, forKey: .createdAt)
try container.encode(lastSignInAt, forKey: .lastSignInAt)
try container.encode(updatedAt, forKey: .updatedAt)
}
}

Expand Down
1 change: 1 addition & 0 deletions Tests/AuthTests/AuthClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class AuthClientTests: XCTestCase {

override func setUp() {
super.setUp()
Current = .mock

eventEmitter = .mock
sessionManager = .mock
Expand Down
2 changes: 1 addition & 1 deletion Tests/AuthTests/MockHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ func json(named name: String) -> Data {

extension Decodable {
init(fromMockNamed name: String) {
self = try! AuthClient.Configuration.jsonDecoder.decode(Self.self, from: json(named: name))
self = try! Current.configuration.decoder.decode(Self.self, from: json(named: name))
}
}

0 comments on commit 69e1389

Please sign in to comment.