From c93cf90d60d7d6ed1ff04a6a51e72ab009f30795 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 30 Jul 2024 08:58:54 -0300 Subject: [PATCH] fix(auth): mark identities last_sign_in_at field as optional (#483) `lastSignInAt`, `updatedAt`, and `createdAt` fields from `UserIdentity` are now optional fields. --- Sources/Auth/Types.swift | 24 ++++++++++++------------ Tests/AuthTests/Resources/user.json | 11 +++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Sources/Auth/Types.swift b/Sources/Auth/Types.swift index a5e536bf..44219bd9 100644 --- a/Sources/Auth/Types.swift +++ b/Sources/Auth/Types.swift @@ -223,9 +223,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable { public var userId: UUID public var identityData: [String: AnyJSON]? public var provider: String - public var createdAt: Date - public var lastSignInAt: Date - public var updatedAt: Date + public var createdAt: Date? + public var lastSignInAt: Date? + public var updatedAt: Date? public init( id: String, @@ -233,9 +233,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable { userId: UUID, identityData: [String: AnyJSON], provider: String, - createdAt: Date, - lastSignInAt: Date, - updatedAt: Date + createdAt: Date?, + lastSignInAt: Date?, + updatedAt: Date? ) { self.id = id self.identityId = identityId @@ -267,9 +267,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable { 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) + createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt) + lastSignInAt = try container.decodeIfPresent(Date.self, forKey: .lastSignInAt) + updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt) } public func encode(to encoder: any Encoder) throws { @@ -280,9 +280,9 @@ public struct UserIdentity: Codable, Hashable, Identifiable, Sendable { 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) + try container.encodeIfPresent(createdAt, forKey: .createdAt) + try container.encodeIfPresent(lastSignInAt, forKey: .lastSignInAt) + try container.encodeIfPresent(updatedAt, forKey: .updatedAt) } } diff --git a/Tests/AuthTests/Resources/user.json b/Tests/AuthTests/Resources/user.json index 0cf2af1c..89a504a2 100644 --- a/Tests/AuthTests/Resources/user.json +++ b/Tests/AuthTests/Resources/user.json @@ -26,6 +26,17 @@ "last_sign_in_at": "2022-04-09T11:23:45Z", "created_at": "2022-04-09T11:23:45.899924Z", "updated_at": "2022-04-09T11:23:45.899926Z" + }, + { + "id": "6c69f399-be1b-467a-9c53-d3753abdd2df", + "user_id": "6c69f399-be1b-467a-9c53-d3753abdd2df", + "identity_id": "6c69f399-be1b-467a-9c53-d3753abdd2df", + "identity_data": { + "sub": "6c69f399-be1b-467a-9c53-d3753abdd2df" + }, + "provider": "github", + "created_at": "2022-04-09T11:23:45.899924Z", + "updated_at": "2022-04-09T11:23:45.899926Z" } ], "created_at": "2022-04-09T11:23:45.874827Z",